Bug 62673 - XSSF worksheet has column range in dimension off by one
Summary: XSSF worksheet has column range in dimension off by one
Status: RESOLVED DUPLICATE of bug 61798
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.17-FINAL
Hardware: All All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-09-04 16:23 UTC by Richard Evans
Modified: 2018-09-04 20:10 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Evans 2018-09-04 16:23:27 UTC
XSSFSheet has this code in the write method:

            if(row.getLastCellNum() != -1) {
                maxCell = Math.max(maxCell, row.getLastCellNum());
...

        if(minCell != Integer.MAX_VALUE) {
            String ref = new CellRangeAddress(getFirstRowNum(), getLastRowNum(), minCell, maxCell).formatAsString();
            if(worksheet.isSetDimension()) {
                worksheet.getDimension().setRef(ref);
            } else {
                worksheet.addNewDimension().setRef(ref);
            }
        }

Arguments to the CellRangeAddress are zero-based:

	/**
	 * Creates new cell range. Indexes are zero-based.

However row.getLastCellNum() returns the zero-based last cell number PLUS ONE:

     * @return short representing the last logical cell in the row <b>PLUS ONE</b>,
     *   or -1 if the row does not contain any cells.
     */

As a result the dimension in the worksheet has the last column number off by one.  A single column sheet with five rows is written with 

<dimension ref="A1:B5"/>

instead of

<dimension ref="A1:A5"/>
Comment 1 Dominik Stadler 2018-09-04 20:10:15 UTC
As far as I see this is already fixed on trunk via bug 61798, r1819404. The next release POI 4.0.0 will be released shortly and will include this fix.

*** This bug has been marked as a duplicate of bug 61798 ***