![](/img/trans.png)
[英]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.