First of All :-) , I am not that proficient in java.
So in below code I am trying to print a two dimensional string returned from method. But unable to do it. Getting type mismatch error. can any one help.
public class ExcelUtilAdvanced {
public String[][] getDatafromExcel(){
int rowCount = sheet.getPhysicalNumberOfRows();
int colCount = sheet.getRow(0).getPhysicalNumberOfCells();
String[][] data = new String[rowCount-1][colCount];
Row row;
Cell cell;
for(int i=1;i<rowCount;i++) {
row = sheet.getRow(i);
for(int j=0;j<colCount;j++) {
cell = row.getCell(j);
data[i-1][j] = format.formatCellValue(cell);
}
}
System.out.println(data);
return data;
}
public static void main(String[] args) {
int rowCount = 2;
int colCount = 7;
ExcelUtilAdvanced eua = new ExcelUtilAdvanced("fileName.xlsx", "sheetName");
String[][] data = new String[rowCount][colCount];
for(int i=1;i<rowCount;i++) {
for(int j=0;j<colCount;j++) {
data[i-1][j]= eua.getDatafromExcel(); //Type Type mismatch: cannot convert from String[][] to String
}
}
}
You are passing a
String[][]object into aStringvariable. I think you can declare and initialize directly theString[][]object passing the result returned by that method.Edit: Also, you have to modify the rest of your code, so you'll able to handle
rowCountandcolCountvariables (maybe you can put them in first method as input parameters), cause you aren't using those inString[][]declarations.Like:
And you have to put
System.out.printlnat the end of each loops, in order to print yourString[][]while you assign values. You can't print just yourdatavariable.General example: