You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by shaal <sh...@gmail.com> on 2012/09/26 18:33:24 UTC

how to deal with the empty cells in poi ?

sample.xls <http://apache-poi.1045710.n5.nabble.com/file/n5711012/sample.xls>  

Please find the attached excel for understanding

Lets consider only the first 3 rows on the attached excel

I am reading the excel from a java file. by which the cells F2,G2,A3,B3 and
E3 are actually empty. 
while the java reads the excel, poi is not recognizing the cells
(F2,G2,A3,B3 and E3).
It is just ignoring the blank cells. But what i want is, I want to recognize
the blanks cells as "" (some empty values).

this can be achieved manually by, writing some texts in the cells
F2,G2,A3,B3 and E3 and deleting the values (texts).

This can be possible for 3 or 4 rows.. But how to make it possible for the
whole sheet. Any idea..?? 

So that all of my empty values should recognize as "" or it can atleast
return "null" 

Plz help.. Its very critical and have to fix it..



--
View this message in context: http://apache-poi.1045710.n5.nabble.com/how-to-deal-with-the-empty-cells-in-poi-tp5711012.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: how to deal with the empty cells in poi ?

Posted by Mark Beardsley <ma...@tiscali.co.uk>.
This crops up fairly regularly and the reason lies in the default bahviour of
the Excel application. When you create a workbook, Excel will only store
information within the file relating to cells/rows that have data in them.
If no one has ever entered anything into, for example, cell D13, then a
record for that cell will not exist in the file. POI will not create records
for missing cell sunless you ask it to do so, and you can by using the
MissingCellPolicy. 

I am not at my own PC now and so cannot point you to an example but, from
memory, this technique allows you to tell POI to behave in a specific way
when it encoounters missing cells in a workbook. Again, from memory, it is
possible, I think, to tell it to return a blank cell, an empty cell or null,
and there may be others. With a bit of googling, I found this example on teh
stackoverflow site

Row r = sheet.getRow(2);
Cell c = r.getCell(5, MissingCellPolicy.CREATE_NULL_AS_BLANK); 

and think it contains all that is relevent here. When you try to get the
cell, simply specify what should happen if a cell is missing.

Hope this helps.

Yours

Mark B



--
View this message in context: http://apache-poi.1045710.n5.nabble.com/how-to-deal-with-the-empty-cells-in-poi-tp5711012p5711015.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org