![](/img/trans.png)
[英]ArrayIndexOutofBoundException - Java - Android - Receiving streaming data and storing in multi-dimensional array Java
[英]Reading Excel file using poi and storing in multi-dimensional array doesn't bring all the data in Java
您好我正在嘗試通過循環將數據從 excel 帶到多維數組,它帶來了除最后一行之外的數據。 請問可以做些什么來修復它?
謝謝。
這是我的代碼:
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();
}
它打印到第 4 行並且不打印最后一行
這是 excel 文件:
編輯:
int rows = ws.getLastRowNum()+1;
這似乎解決了這個問題,如果有任何其他更好的方法可以解決它,請告訴我。
謝謝
int rows = ws.getLastRowNum()+1;
這似乎解決了這個問題,如果有任何其他更好的方法可以解決它,請告訴我。
謝謝
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.