Bug 60389 - XSSFSheet getLastRowNum return strange value
Summary: XSSFSheet getLastRowNum return strange value
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.15-FINAL
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2016-11-18 06:53 UTC by Zero
Modified: 2016-11-18 08:27 UTC (History)
0 users

excel formated last row (8.23 KB, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
2016-11-18 06:58 UTC, Zero

Note You need to log in before you can comment on or make changes to this bug.
Description Zero 2016-11-18 06:53:37 UTC
When i get last row of sheet, getLastRowNum return last row formated instead last row has data.
Have another way to get last row have data?
Thank you very much for reading and support.
Comment 1 Zero 2016-11-18 06:58:03 UTC
Created attachment 34459 [details]
excel formated last row

excel file added formated last row (1048576) as currency (decimal: 0; symbol: $)

test code:
public void testGetLastRowNum() throws IOException {
  String filePath = "test-data/60389_get_last_row_num.xlsx";
  try (XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream(filePath))) {
    XSSFSheet sheet = wb.getSheetAt(0);
Comment 2 Javen O'Neal 2016-11-18 08:06:31 UTC
getLastRowNum returns the row number of the last physical row in the sheet. This is equivalent to Ctrl+Down in Excel

The Sheet interface doesn't have a function to get the last row containing at least one non-blank cell.

You will need to iterate over the rows (ideally a reverse iterator) and iterate over cells in each row to determine if that row is blank, then return the row number of the last non-blank row. This sounds like it could be expensive.

You may want to look at http://stackoverflow.com/questions/38204944/apache-poi-check-if-a-column-is-empty/38238218#38238218 for ideas on efficient iteration.

Since this is not a bug but a usage question, I. If you have more questions, please ask them on user@poi.apache.org mailing list. https://poi.apache.org/mailinglists.html
Comment 3 Zero 2016-11-18 08:27:28 UTC
Thank you very much, Javen O'Neal