Apache poi get the used row number

Hi All,
I have usedint totalRows = ExcelWSheet.getPhysicalNumberOfRows() to get the used number of rows in a XSSFWorksheet, but it is not returning the actual result.
Is there any way to get the current row number or used number of rows?
I have already tried

ExcelWSheet.getLastRowNum(), but it returned a big number. Please help me to solve this issue?

I appreciate your help.

Thanks,
Nisha

Nisha Train Asked on December 6, 2014 in Selenium WebDriver.

Hi Nisha
ExcelWSheet.getLastRowNum() it gives you the lost row number containing data
Suppose if you have data in First Row and 50 th row it will return Value 50
So might possible you have Data there

on December 6, 2014.
Add Comment
1 Answer(s)

Hi Nisha,

Yes that happens with Excel. Reason of that is that earlier there were some data in the excel rows but not you have cleared the cell but those cells are actually initialised. I can explain this how it works but you wil get confuse on this. Work arounds for this are:

1) Create a new sheet and make sure you just use first few rows.
2) Select the number of rows in the excel and delete those rows even if they are blank and does not contain any data. Make sure that you just not delete the cell rather delete the complete rows. Th number of rows to be deleted = the number you get in your result when you use the ExcelWSheet.getLastRowNum().

Regards,
Lakshay Sharma

xLov3rDns Professor Answered on December 8, 2014.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.