Bug 60389

Summary: XSSFSheet getLastRowNum return strange value
Product: POI Reporter: Zero <tuyenivt>
Component: XSSFAssignee: POI Developers List <dev>
Severity: normal    
Priority: P2    
Version: 3.15-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: All   
Attachments: excel formated last row

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