1

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.

plaidshirt
  • 5,189
  • 19
  • 91
  • 181
  • 2
    you are getting row #0 as a base and then wondering why you don't get the row number? try using ``sh.getFirstRowNum()`` and ``sh.getLastRowNum()`` to get first and last row indexes. And by the way, ``Sheet`` implements ``Iterable`` so you can write ``for(Row r : sh) {}`` – spi Mar 21 '19 at 14:43

1 Answers1

2

It gives right number of rows on a sheet:

int rnum = sheet.getLastRowNum() - sheet.getFirstRowNum();
plaidshirt
  • 5,189
  • 19
  • 91
  • 181