Java 多注释ApachePOI

Java 多注释ApachePOI,java,excel,apache-poi,Java,Excel,Apache Poi,我正在尝试将多个注释分配给多个单元格。打开文件时,excel抱怨“excel在…中发现无法读取的内容,是否要恢复此工作簿的内容?” 当我只有一条评论时,它可以工作,但有两条或更多评论失败。请参见下面的我的代码: String oper = "OPERATION TO DO AFTER UPLOAD"; Cell c = row.createCell(0); c.setCellType(Cell.CELL_TYPE_STRING); c.setCellValue(o

我正在尝试将多个注释分配给多个单元格。打开文件时,excel抱怨“excel在…中发现无法读取的内容,是否要恢复此工作簿的内容?”

当我只有一条评论时,它可以工作,但有两条或更多评论失败。请参见下面的我的代码:

    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文档表:
-->它上面写着SXSSF注释-->No(我证明你可以有1条注释:)

你使用哪个版本的
POI
,你使用的是
HSSF
还是
XSSF
?乍一看,你的代码没有问题。我使用类似的代码创建了几十条注释,它可以毫无问题地工作。必要的步骤都在那里。重复使用
绘图
CreationHelper
也不是问题。您是否看到
CreateDrawingPachur()
WRT上的警告只执行一次,以及它将如何吃掉您的HSSF工作表中已有的任何绘图/注释?2Sebastian。我使用3.10-FINAL。我正在使用XSSF(SXSSFWorkbook)。这可能是
SXSSF
的一个限制。看看这个:
SXSSF
有一个相当有限的功能集,并且在列表中指出,
SXSSF
不支持注释。您可以尝试将代码更改为纯
XSSF
,看看问题是否仍然存在@Gagravarr应该能够告诉你,如果
SXSSF
真的对单元格评论有问题,因为他是POI的贡献者。我会这么认为@Gagravarr你能确认一下吗?我认为这真的可能是SXSSF的局限性。。。(单个电子表格中只能有一条注释)。我应该为此提出功能请求吗?(我知道SXSSF是只写的,不支持所有功能,但仍然很有用)