I need to read an excel file and like others, I use Jakarta POI APi for
this purpose.
But the problem is that I have to know number of cells those contain
data before starting
the read so that I can stop reading when there is no more data. Null
check is not of use
because there may be blank cells among cells containing data.
Can you guide me the proper way of using POI that can solve my problem.
Thanks in advance.
Can Odabasioglu
Gordon Beaton - 18 Apr 2006 16:18 GMT
> I need to read an excel file and like others, I use Jakarta POI APi
> for this purpose. But the problem is that I have to know number of
[quoted text clipped - 4 lines]
> Can you guide me the proper way of using POI that can solve my
> problem.
Do these methods not do what you want?
HSSFSheet.getFirstRowNum()
HSSFSheet.getLastRowNum()
HSSFRow.getFirstCellNum()
HSSFRow.getLastCellNum()
/gordon

Signature
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
Rajah - 18 Apr 2006 16:30 GMT
Can,
I have written a small routine called isCellBlank. It looks like this:
protected boolean isCellBlank(HSSFCell cell) {
if (null == cell) return true; // If cell is null let's return
true.
return (cell.getCellType() == HSSFCell.CELL_TYPE_BLANK) ;
}
I am not sure if you can distinguish between a null cell and a blank
cell that is in the midst of other, valid data. If so, you probably
want to multiply the physical number of rows by the number of columns.
You might want to use a snippet like this:
int rows = sheet.getPhysicalNumberOfRows();
for (int r = 0; r < rows; r++)
{
HSSFRow row = sheet.getRow(r);
int cells = row.getPhysicalNumberOfCells();
...
}
and accumulate the number of cells.