Jakarta POI APi

C

canodabasioglu

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
 
G

Gordon Beaton

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.

Do these methods not do what you want?

HSSFSheet.getFirstRowNum()
HSSFSheet.getLastRowNum()

HSSFRow.getFirstCellNum()
HSSFRow.getLastCellNum()

/gordon
 
R

Rajah

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top