[英]How to get more than 255 columns in an excel sheet using Apache POI 3.6
[英]Reading Excel sheet using jxl is not working more than 255 rows
我嘗試使用jxl jar讀取舊格式的Excel工作表,它工作正常,但在255行后拋出錯誤:
java.lang.ArrayIndexOutOfBoundsException: 255
我無法使用Poi jar
閱讀,因為它是舊格式,非常感謝任何幫助!
下面是下面給出的Java代碼段:
public HashMap<String, Float> readAllRowsOnePoint(String path, String sheetname) throws BiffException, IOException {
System.out.println("Path download" + path);
FileInputStream fs = new FileInputStream(path);
Workbook wb = Workbook.getWorkbook(fs);
Sheet sheet = wb.getSheet(sheetname);
// To get the number of rows present in sheet
int totalNoOfRows = 500;
System.out.println("The rows count is " + totalNoOfRows);
HashMap<String, Float> map = new HashMap<>();
for (int row = 2; row < totalNoOfRows; row++) {
try {
Cell dateCell = null;
Cell psidCell = null;
Cell nameCell = null;
Cell quantityCell = null;
Cell billingCell = null;
try {
dateCell = sheet.getCell(0, row);
psidCell = sheet.getCell(1, row);
nameCell = sheet.getCell(2, row);
quantityCell = sheet.getCell(8, row);
billingCell = sheet.getCell(10, row);
} catch(Exception e){
// e.printStackTrace();
}
String date = dateCell.getContents().trim();
String psid = psidCell.getContents().trim();
String name = nameCell.getContents().trim();
String quantity = quantityCell.getContents().trim();
String billing = billingCell.getContents().trim();
System.out.println();
} catch(Exception e) {
System.out.println("Error in row " + row + " Exception " );
}
}
return map;
}
您的問題在這條線上:
for (int i = 0 ; i < 1000; i++)
您不能只插入1000
因為您不知道每個工作表是否都有1000行。 只需使用Sheet
對象中的getRows()
方法(如該行上方的注釋中所示):
for (int i = 0 ; i < s.getRows(); i++)
這樣一來,您就不會收到ArrayIndexOutOfBoundsException,因為循環在所有行完成之后會停止。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.