使用 Apache POI 获取行数

Get number of rows with Apache POI

我尝试使用 Apache POI 计算 xls 文件中的行数。文件包含 300 行,但我只得到 24 行作为这两个命令的输出。

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

文件中行与行之间没有空行。

它在 sheet:

上给出了正确的行数
int rnum = sheet.getLastRowNum() - sheet.getFirstRowNum();