I am trying to read excel file using POI with code which looks as
follows
HSSFWorkbook wb = new HSSFWorkbook(stream, false);
HSSFSheet sheet = wb.getSheetAt(sheetNo);
int noOfRows = sheet.getPhysicalNumberOfRows();
for (int r = 0; r < noOfRows; r++) {
HSSFRow row = sheet.getRow(r);
if(row == null) break;
//read data
}
What happens is if say I have an excel with 10 rows then i select the
data in last 5 row and delete it and save the excel. Now if I read the
excle again I assume that
int noOfRows = sheet.getPhysicalNumberOfRows(); should give me 5. But
still give me 10 and hence my program fails.
Anyone knows how to handle it?
Oliver Wong - 04 Aug 2006 20:10 GMT
>I am trying to read excel file using POI with code which looks as
> follows
[quoted text clipped - 17 lines]
>
> Anyone knows how to handle it?
Look at the contents of the rows. They probably have empty strings, or
null or something. Come up with a rule to differentiate "fake" rows from
"real" rows. Implement your count manually based on that rule.
- Oliver