使用jxl读取Excel工作表不能工作超过255行

我尝试阅读使用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,因为循环在所有行完成后停止。