[英]Reading Excel file using poi and storing in multi-dimensional array doesn't bring all the data in Java
Hello I am trying to bring data from excel to multi-dimensional array by looping, it brings the data except for the last row.您好我正在尝试通过循环将数据从 excel 带到多维数组,它带来了除最后一行之外的数据。 What could be done to fix it please?
请问可以做些什么来修复它?
Thanks.谢谢。
Here is my code:这是我的代码:
String filePath = "C:\\testXL.xlsx";
FileInputStream fis = new FileInputStream(filePath);
XSSFWorkbook wb = new XSSFWorkbook(fis);
XSSFSheet ws = wb.getSheet("Sheet1");
int rows = ws.getLastRowNum(); //will give us how many rows until the last row
int cols = ws.getRow(0).getLastCellNum();
String[][] rowCol = new String[rows][cols];
for (int r = 0; r < rows; r++){
XSSFRow myRow = ws.getRow(r);
for (int c = 0; c<cols; c++){
String value = myRow.getCell(c).toString();
rowCol[r][c] = value;
System.out.print(rowCol[r][c]+ "\t");
}
System.out.println();
}
it prints upto 4th row and doesn't print the last row它打印到第 4 行并且不打印最后一行
This is the excel file:这是 excel 文件:
Edit:编辑:
int rows = ws.getLastRowNum()+1;
This seems to solve the issue, if there is any other better way to solve it please let me know.这似乎解决了这个问题,如果有任何其他更好的方法可以解决它,请告诉我。
Thanks谢谢
int rows = ws.getLastRowNum()+1;
This seems to solve the issue, if there is any other better way to solve it please let me know.这似乎解决了这个问题,如果有任何其他更好的方法可以解决它,请告诉我。
Thanks谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.