javaapache-poihssf

Get number of rows with Apache POI


I try to count number of rows in a xls file with Apache POI. File contains 300 rows, but I get just 24 as output of both of these commands.

int noOfColumns = sh.getRow(0).getPhysicalNumberOfCells();
int noOfColumns = sh.getRow(0).getLastCellNum();

There aren't any empty rows between lines in file.


Solution

  • It gives right number of rows on a sheet:

    int rnum = sheet.getLastRowNum() - sheet.getFirstRowNum();