Skip to content

Commit

Permalink
Merge pull request #536 from frank-weinberg/bugfix/534
Browse files Browse the repository at this point in the history
properly handle cells with existing comments on xlsx export
  • Loading branch information
frank-weinberg authored Sep 18, 2022
2 parents e941719 + 68405a2 commit 4f64050
Showing 1 changed file with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -654,14 +654,20 @@ private static void setComment(Cell cell, String text) {
Row row = cell.getRow();
Sheet sheet = row.getSheet();
CreationHelper factory = sheet.getWorkbook().getCreationHelper();
Drawing<?> drawing = sheet.createDrawingPatriarch();

ClientAnchor anchor = factory.createClientAnchor();
anchor.setCol1(cell.getColumnIndex());
anchor.setCol2(cell.getColumnIndex() + 2);
anchor.setRow1(row.getRowNum());
anchor.setRow2(row.getRowNum() + 3);
Comment comment = drawing.createCellComment(anchor);

Comment comment = cell.getCellComment();

if (comment == null) {
Drawing<?> drawing = sheet.createDrawingPatriarch();

ClientAnchor anchor = factory.createClientAnchor();
anchor.setCol1(cell.getColumnIndex());
anchor.setCol2(cell.getColumnIndex() + 2);
anchor.setRow1(row.getRowNum());
anchor.setRow2(row.getRowNum() + 3);
comment = drawing.createCellComment(anchor);
}

RichTextString str = factory.createRichTextString(text);
comment.setString(str);
comment.setAuthor("CRG");
Expand Down

0 comments on commit 4f64050

Please sign in to comment.