多条评论 apache poi [英] Multiple comments apache poi

查看:27
本文介绍了多条评论 apache poi的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为多个单元格分配多个注释.打开文件时 excel 抱怨Excel 在...中发现不可读的内容,您要恢复该工作簿的内容吗?"

I am trying to assign multiple comments to multiple cells. When opening the file excel complains that "Excel found unreadable content in ... do you want to recover the content of this workbook?"

当我只有一条评论有效时,两条或更多评论就会失败.请参阅下面的代码:

When I have only one comment it works, 2 or more comments it fails. See my code below:

    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);

有什么问题吗?我知道你只需要创建一次绘图,但我没有越过那个......

What is the problem there? I understand you have to create the Drawing only once but I did not cross that ....

推荐答案

因此,当使用 SXSSF 时,您不能使用注释(我猜您应该不会).您只能添加一个在电子表格中有效的评论,但有点无用.

So as it turns out when using SXSSF you can not use comments (you should not I guess). You can only add one comment that will be valid in spreadsheet that is kinda useless.

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

For details see table on poi documentation located here: poi.apache.org/spreadsheet --> It says right there for SXSSF Comments --> No (well I proved that you can have 1 comment :) )

这篇关于多条评论 apache poi的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆