修复SXSSFWorkbook调用setComment时错位的问题

This commit is contained in:
Looly
2023-03-12 13:18:59 +08:00
parent 4cc18740a3
commit def6fe2b60
3 changed files with 56 additions and 1 deletions

View File

@@ -455,12 +455,18 @@ public class CellUtil {
final CreationHelper factory = wb.getCreationHelper();
if (anchor == null) {
anchor = factory.createClientAnchor();
// 默认位置,在注释的单元格的右方
anchor.setCol1(cell.getColumnIndex() + 1);
anchor.setCol2(cell.getColumnIndex() + 3);
anchor.setRow1(cell.getRowIndex());
anchor.setRow2(cell.getRowIndex() + 2);
// 自适应
anchor.setAnchorType(ClientAnchor.AnchorType.MOVE_AND_RESIZE);
}
final Comment comment = drawing.createCellComment(anchor);
// https://stackoverflow.com/questions/28169011/using-sxssfapache-poi-and-adding-comment-does-not-generate-proper-excel-file
// 修正在XSSFCell中未设置地址导致错位问题
comment.setAddress(cell.getAddress());
comment.setString(factory.createRichTextString(commentText));
comment.setAuthor(StrUtil.nullToEmpty(commentAuthor));
cell.setCellComment(comment);