我正在尝试将多个注释分配给多个单元格。打开文件时,Excel 提示“Excel 在...中发现了不可读的内容,您想恢复此工作簿的内容吗?”
当我只有一条评论时,它可以工作,如果有 2 条或更多评论,它就会失败。请参阅下面的代码:
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);
那里有什么问题?我知道您只需创建一次绘图,但我没有越过这一点....
最佳答案
事实证明,在使用 SXSSF 时,您不能使用注释(我猜您不应该这样做)。您只能添加一条在电子表格中有效的评论,这有点无用。
有关详细信息,请参阅此处的 poi 文档表格: poi.apache.org/spreadsheet --> 上面写着 SXSSF 评论 --> 否(好吧,我证明你可以有 1 条评论:))
关于java - 多个评论 apache poi,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25766839/