多条评论apache poi

时间:2014-09-10 13:32:35

标签: 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);

那有什么问题?我知道你必须只创建一次绘图,但我没有跨过那个......

1 个答案:

答案 0 :(得分:2)

因此,当使用SXSSF时,你不能使用评论(我不应该猜)。您只能添加一个在电子表格中有效且无用的评论。

有关详细信息,请参阅此处的poi文档表: poi.apache.org/spreadsheet - >它说的就是SXSSF 评论 - >没有(我证明你可以有1条评论:))