It does help, but not the way I would have written the POI code to parse a row.

yeah, I did see how getLastCellNum() differs from getPhysicalNumberOfCells().

I found this on the Net, and I was iterating through the row as follows:
for(Iterator cit = row.cellIterator(); cit.hasNext(); ) {
   HSSFCell cell = (HSSFCell)cit.next();
}
However, this only gets back cells with data in them ... so I don't know why there is even a CELL_TYPE_BLANK.
The API docs don't offer much information on this.
I presumed that getting the cell iterator would internally handle these null cells and they would register as CELL_TYPE_BLANK.

Ultimately what DOES work is getting the number of cells from getLastCellNum() .
The the for loop would look like:
for(short i=0;    i<row.getLastCellNum() ;i++  ) {
   HSSFCell cell = row.getCell(i);
   if( null = cell) {
         System.out.println("cell is null");
   } else {
System.out.println("cell is NOT null: now I can check for cell type");
   }
}
This method seems horribly inefficient, but it works.

Andy Chien wrote:
Please feel free to correct me if I am wrong or mistaken.

The cell form representation you see in Microsoft Excel is not the true physical representation _on_file_. POI works directly _on_xls_file_, this is where I think you are getting the mixed up.

In xls file format, cell is not created unless it has been used or contains something. That is why you are not seeing a full 22 cells because the blank cells are simply not present!! Please note the difference from the Microsoft Excel graphical representation, which puts things in the location (causing blank cell).

p.s. If you think about it closely, why waste the data structure storing blank cells?

Now that the theoretical piece is done, if you are using the usermodel the way that you can get the last of anything is the follow.

http://poi.apache.org/apidocs/index.html

From HSSFSheet lookup function that says getLastRowNum() to get last row in a sheet From HSSFRow lookup function that says getLastCellNum() to get last cell in a row

To find out whether if the cells are empty do a loop through the area that's less than getLastRowNum() or getLastCellNum() if any return "null" then they are of type CELL_BLANK.


Hope this helps.

Andy



Tom Holmes Jr. wrote:
I'm reading in an Excel file successfully. I can get the POIFileSystem, the Workbook, and the Worksheet.

I can get all the rows, and now I am trying to get a row (HSSFRow). The first row is headers, and there are 22 columns, so I get these 22 fields. The other rows are all data.

However, some of these rows have blank/null values in those columns. So, when I get row.getPhysicalNumberOfCells(), I don't get 22 columns.

I am using a switch to check for all the cell types, and I am looking for a CELL_BLANK value and I don't see it.

Is there something I need to do to fix this?    Thanks!
Tom




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to