I am trying to assign multiple comments to multiple cells. When opening the file excel complains that "Excel found unreadable content in ... do you want to recover the content of this workbook?"
When I have only one comment it works, 2 or more comments it fails. See my code below:
String oper = "OPERATION TO DO AFTER UPLOAD";
Cell c = row.createCell(0);
c.setCellType(Cell.CELL_TYPE_STRING);
c.setCellValue(oper);
c.setCellStyle(headerStyle);
CreationHelper factory = wb.getCreationHelper();
Drawing drawing = sh.createDrawingPatriarch();
//comment for operation
ClientAnchor anchor = factory.createClientAnchor();
anchor.setCol1(c.getColumnIndex());
anchor.setCol2(c.getColumnIndex()+1);
anchor.setRow1(row.getRowNum());
anchor.setRow2(row.getRowNum()+3);
Comment comment = drawing.createCellComment(anchor);
RichTextString str = factory.createRichTextString("Please note that UPDATE will translate to INSERT (if ENTITY_ID column is empty) or UPDATE (if ENTITY_ID column is a number)");
comment.setString(str);
comment.setAuthor("me");
// Assign the comment to the cell
c.setCellComment(comment);
String entity_id = "ENTITY ID";
c = row.createCell(1);
c.setCellType(Cell.CELL_TYPE_STRING);
c.setCellValue(entity_id);
c.setCellStyle(headerStyle);
// comment for EntityID
ClientAnchor anchorEid = factory.createClientAnchor();
anchorEid.setCol1(c.getColumnIndex());
anchorEid.setCol2(c.getColumnIndex() + 1);
anchorEid.setRow1(row.getRowNum());
anchorEid.setRow2(row.getRowNum() + 3);
Comment commentEid = drawing.createCellComment(anchorEid);
RichTextString strEid = factory
.createRichTextString("Please note that UPDATE will translate to INSERT (if ENTITY_ID column is empty) or UPDATE (if ENTITY_ID column is a number)");
commentEid.setString(strEid);
commentEid.setAuthor("me");
// Assign the comment to the cell
c.setCellComment(commentEid);
What is the problem there? I understand you have to create the Drawing only once but I did not cross that ....