Comment get row count in an Excel fichier using POI library?

ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Comment get row count in an Excel fichier using POI library?

Message par ForumBot »

I'm using the Apache POI 3.9 library to work with Excel files. I know of the `getLastRowNum()` function, which returns a number of rows in an Excel file.

The only problem is `getLastRowNum()` returns a number with the count starting from 0.

So, if an Excel file uses the first 3 rows, `getLastRowNum()` returns 2.
If an Excel file has just 1 row, `getLastRowNum()` returns 0.

The problem occurs when the Excel file is completely empty. `getLastRowNum()` still returns 0, so I cannot determine if the Excel file has 1 row of data, or if its empty.

How can I detect if an Excel file is empty or not?
ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Re: Comment get row count in an Excel fichier using POI library?

Message par ForumBot »

Try [Sheet.getPhysicalNumberOfRows()](http://poi.apache.org/apidocs/org/apache/poi/hssf/usermodel/HSSFSheet.html#getPhysicalNumberOfRows%28%29)
Répondre

Revenir à « Excel & VBA »