Created attachment 29988 [details] trivial test case, created in Excel 2010 Exception in thread "main" java.lang.NullPointerException at org.apache.poi.ss.util.CellReference.<init>(CellReference.java:88) at org.apache.poi.xssf.usermodel.XSSFSheet.getTopRow(XSSFSheet.java:1181) at poi.ReadTest.main(ReadTest.java:22) for the second sheet (note the first visible row of first sheet is 2). File is created in Excel 2010, saving it in xls format (Excel 97-2003) solves the issue. To reproduce: Workbook wb = WorkbookFactory.create(new File("c:/0/xxx.xlsx")); for (int si = 0; si < wb.getNumberOfSheets(); si++) { Sheet sh = wb.getSheetAt(si); System.out.println(sh.getSheetName() + "/" + sh.getTopRow()); }
It seems POI expects that sheets do have an attribute like this in sheetX.xml: topLeftCell="A2" However for your test-example, there is no such entry in sheet2.xml, seems the attribute is only there if a non-default top-row is set, but poi does not expect that. Other test-examples also don't have the attribute, seems a simple null check is missing. BTW, the same applies for getLeftCol() for XSSF/SXSSF.
Fixed with SVN r1493686 M src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java M src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java A test-data/spreadsheet/54607.xlsx Added a null-check as well as test-cases covering these changes.