Bug 57151

Summary: [PATCH] Document CellRangeAddress
Product: POI Reporter: Viliam Anirud <a6537691>
Component: XSSFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: minor    
Priority: P2    
Version: 3.11-dev   
Target Milestone: ---   
Hardware: All   
OS: All   
Attachments: The patch (generated from SVN on the current revision)

Description Viliam Anirud 2014-10-27 12:58:01 UTC
Created attachment 32150 [details]
The patch (generated from SVN on the current revision)

In the current version of POI it is easy to generate merged cells in an XLSX document, that excel fails to read, if merged regions overlap or are of zero or negative size.

My patch is very simple, but helpful. It documents the constructor of CellRangeAddress, because to Java developers it is not obvious, that the end-index is included in the range. The common practice in Java API is that the end index is the index of the first not-included element.

Secondly, it adds the check, that lastRow (lastCol) cannot be less than firstRow (firstCol). This check may cause minor backward incompatibility, but only in cases, when the generated output was already unreadable by Excel. Similar check was already implemented for the HSSF format, in InternalSheet.java, line 447 (addMergedRegion method). So it will not cause incompatibility here, the error will just be reported earlier.

It could be helpful to add overlap check, but this will be an more in-depth patch. HSSF format, unlike XSSF, seems to forgive this error: http://apache-poi.1045710.n5.nabble.com/XSSFSheet-addMergedRegion-giving-excel-error-td3389764.html
Comment 1 Dominik Stadler 2014-10-30 07:51:31 UTC
Thanks for the patch, applied via r1635389.


I also added some more unit tests to verify the changes, would be nice if you can provide an accompanying unit-test as part of future patches.