We are using poi3.0.2.jar file. where the code(attached) works fine for xls files wb=WorkbookFactory.create(fin); Sheet sheet = wb.getSheetAt(0); Row row; Cell cell; for(int r = 0; r < rows; r++) { System.out.println(); row = sheet.getRow(r); if(row != null) { for(int c = -1; c < cols; c++) { cell = row.getCell((short)c); } where as if I pass xlsx files its giving followig error. java.lang.IllegalArgumentException: Cell index must be >= 0 at org.apache.poi.xssf.usermodel.XSSFRow.getCell(XSSFRow.java:191) at org.apache.poi.xssf.usermodel.XSSFRow.getCell(XSSFRow.java:178) at org.apache.poi.xssf.usermodel.XSSFRow.getCell(XSSFRow.java:35) at ReadExcel.readBoth(ReadExcel.java:190) at ReadExcel.main(ReadExcel.java:39) The problem is with row.getCell(-1) this method returns null in POI3.0.2 the same method throws IllegalArgumentException in POI3.5 So we need to change the code?
row.getCell(-1) is not a valid thing to ask for As the error message tells you, cells start at 0. Either ask for cells from 0 onwards, or use an iterator.