Apache POI Comment Excel

Posted by Marquinio on Stack Overflow See other posts from Stack Overflow or by Marquinio
Published on 2010-05-07T01:58:56Z Indexed on 2010/05/07 2:38 UTC
Read the original article Hit count: 411

Filed under:
|
|
|

I need to add a comment to an HSSF Cell in Excel. Everything works fine the very first time but if I open the same file and run the code again it corrupts the file.

I've also noticed that I need to create a Drawing object on a Sheet only once:

_sheet.createDrawingPatriarch();

If the line above gets executed more than once comments will not work.

So has anyone tried adding comments to Cells, closing the file, opening the file again and trying to add more comments to different cells?

The below code works but if I open the file again then comments are not added, plus the file gets corrupted!!!

Is there a way to get the existing Drawing object from a Sheet?

Any ideas appreciated. Thanks!!

_drawing = (HSSFPatriarch) _sheet.createDrawingPatriarch();

Row row = _sheet.getRow(rowIndex_);
Cell cell = row.getCell(0);
CreationHelper factory = _workbook.getCreationHelper();

HSSFAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, (short)4, 2, (short)6, 5);
        org.apache.poi.ss.usermodel.Comment comment = _drawing.createComment(anchor);
RichTextString str = factory.createRichTextString("Hello, World "+rowIndex_);
comment.setString(str);

  cell.setCellComment(comment);

© Stack Overflow or respective owner

Related posts about apache

Related posts about poi