Bug 51989 - Cells that contain only comments are missing in XSSFRow
Summary: Cells that contain only comments are missing in XSSFRow
Status: RESOLVED INVALID
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.7-FINAL
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-10-07 10:30 UTC by Rick
Modified: 2012-02-27 09:18 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rick 2011-10-07 10:30:52 UTC
If I add a comment to an empty cell within Excel I can
read this cell comment with XSSFSheet#getCellComment(int row, int column)
but when I try to get the according cell from the Row object by #getCell(int cellnum) I do get null returned. I actually would expect a blank cell with the comment on it as return value.
Comment 1 Yegor Kozlov 2012-02-27 09:18:08 UTC
By default, Row#getCell returns what is physically stored in the workbook stream and in your case it is null. 

However, you can control what to do when getting missing or blank cells  with

        Workbook.setMissingCellPolicy(MissingCellPolicy missingCellPolicy);

there are three options:


    /** Missing cells are returned as null, Blank cells are returned as normal */
    public static final MissingCellPolicy RETURN_NULL_AND_BLANK = new MissingCellPolicy();
    /** Missing cells are returned as null, as are blank cells */
    public static final MissingCellPolicy RETURN_BLANK_AS_NULL = new MissingCellPolicy();
    /** A new, blank cell is created for missing cells. Blank cells are returned as normal */
    public static final MissingCellPolicy CREATE_NULL_AS_BLANK = new MissingCellPolicy();

If you expect a blank cell then call 

workbook.setMissingCellPolicy(MissingCellPolicy.CREATE_NULL_AS_BLANK );

after constructing your workbook.

Yegor