Bug 63749 - sheet.getLastRowNum() returns 0 when there are no rows in the sheet
Summary: sheet.getLastRowNum() returns 0 when there are no rows in the sheet
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: POI Overall (show other bugs)
Version: 3.17-FINAL
Hardware: Macintosh All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-09-15 10:11 UTC by Nathan
Modified: 2019-12-15 17:29 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nathan 2019-09-15 10:11:59 UTC
When there are no rows created in the sheet, sheet.getLastRowNum() returns 0 but when there is 1 row created, sheet.getLastRowNum() also returns 0. Shouldn't sheet.getLastRowNum() return -1 for sheet that has no rows?

This is causing issues when you try to create a new row based on the last row number. Due to the above issue, the first row that gets created will start from the 2nd row instead of the very top.

private Row row;

    public void createRow() {
        row = sheet.createRow(sheet.getLastRowNum() + 1);
    }
Comment 1 Dominik Stadler 2019-11-17 11:50:37 UTC
This would affect other methods as well, e.g. Sheet.getFirstRowNum().

Row.getFirstCellNum() and Row.getLastCellNum() already return -1 in this case.
Comment 2 Dominik Stadler 2019-12-15 17:29:09 UTC
With r1871589 we now return -1 in all getFirstRow/getFirstColumn calls in all three implementations (HSSF, XSSF, SXSSF) and thus should be consistent in how this is handled.