Bug 62810 - AreaReference ctor looses sheet name if rows or columns swapped
Summary: AreaReference ctor looses sheet name if rows or columns swapped
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: SS Common (show other bugs)
Version: 4.0.0-FINAL
Hardware: PC Mac OS X 10.1
: P2 major (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-10-09 13:46 UTC by David Gauntt
Modified: 2019-01-13 17:15 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Gauntt 2018-10-09 13:46:02 UTC
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 ***/
Comment 1 Dominik Stadler 2019-01-13 17:15:43 UTC
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.