java - 多个评论 apache poi

标签 java excel apache-poi

我正在尝试将多个注释分配给多个单元格。打开文件时,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/

相关文章:

java - 如何在 Java Azure 函数中使用事件中心触发器

java - java中数组的动态值初始化

vba - If * Then * 和条件是什么意思

java - 尝试读取 Excel 文件时出现非法状态异常

java - apache poi 从 xlsx 文件获取工作表 xml 的方法是什么?

java - java中如何获取不同范围内不同概率的随机数?

java - 如何在 Elasticsearch 上使用嵌套聚合?

asp.net - 超链接数据未在 radgrid excel 导出中导出

java - XWPFDocument - getPageCount

java - POI Java Excel解决方案——缩进值