The constructor public AreaReference(CellReference topLeft, CellReference botRight, SpreadsheetVersion version) loses the sheet name if the topLeft is below or to the right of botRight. The unit test below writes the following to the System console: topLeft=Sheet0!$B$2 bottomRight=Sheet0!$K$6 goodAreaRef=Sheet0!$B$2:$K$6 badAreaRef=$B$2:$K$6 /*** Start of unit test code ***/ private static void areaReferenceCtorTest(XSSFSheet sheet) { final String sheetName = sheet.getSheetName(); final CellReference topLeft = new CellReference(sheetName, 1, 1, true, true); final CellReference bottomRight = new CellReference(sheetName, 5, 10, true, true); final AreaReference goodAreaRef = new AreaReference(topLeft, bottomRight, SpreadsheetVersion.EXCEL2007); final AreaReference badAreaRef = new AreaReference(bottomRight, topLeft, SpreadsheetVersion.EXCEL2007); System.out.println(String.format("topLeft=%s", topLeft.formatAsString())); System.out.println(String.format("bottomRight=%s", bottomRight.formatAsString())); System.out.println(String.format("goodAreaRef=%s", goodAreaRef.formatAsString())); System.out.println(String.format("badAreaRef=%s", badAreaRef.formatAsString())); } /*** End of unit test code ***/
This is fixed now via r1851209, when area references are swapped, we now keep a sheet-reference in place. Thanks for the report and unit-test code.