【发布时间】:2021-09-14 04:16:06
【问题描述】:
首先:-),我不是很精通java。
所以在下面的代码中,我试图打印从方法返回的二维字符串。但做不到。获取类型不匹配错误。谁能帮忙。
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
}
}
}
【问题讨论】:
-
data[i-1][j]是String。getDatafromExcel()返回一个由String数组组成的数组。所以不适合。你想在这里做什么? -
想要将方法返回的数组存储在字符串数组中。如答案中所述,我没有正确接收数据。
标签: java excel selenium apache-poi r.java-file