2

I have a big problem with Apache POI.

    A       B       C       D
1   text    text    text    text
2                   comment           
3   text    text    text    text

In this example row 2 is empty, C2 has no text, but a comment.

If I want to get row 2, POI will return null.

How can I get a comment from an empty cell in an empty row?

rgettman
  • 176,041
  • 30
  • 275
  • 357
Smoothi
  • 283
  • 1
  • 3
  • 15

1 Answers1

2

To fetch arbitrary comments, without going via the Cell directly, you can use Sheet.gteCellComment(int row, int cell)

From your example, to get the comment in C2, do something like:

CellReference ref = new CellReference("C2")
Comment commentC2 = sheet.getCellComment(ref.getRow(), ref.getCol());
Gagravarr
  • 47,320
  • 10
  • 111
  • 156
  • Hey :), thank you for this answer. It works for comments, but what can I do, if I have an empty cell with cellstyle only? Is there a solution, too? – Smoothi Dec 23 '14 at 01:41
  • If a cell is explicitly styled, it'll be returned as a cell of type Blank. If it's only implicitly styled, you'll need to fetch the default styling off the row – Gagravarr Dec 23 '14 at 02:00
  • unfortunately not...the row has no style and the cell is not blank – Smoothi Dec 29 '14 at 18:20
  • i'm sorry, the problem was that i used a style sheet (from styles and formatting)... the XSSFSheet does'nt read a foregroundcolor from a standard style sheet – Smoothi Jan 06 '15 at 11:22