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);