Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用ApachePOI创建的单元格注释具有透明的背景_Java_Excel_Apache Poi - Fatal编程技术网

Java 使用ApachePOI创建的单元格注释具有透明的背景

Java 使用ApachePOI创建的单元格注释具有透明的背景,java,excel,apache-poi,Java,Excel,Apache Poi,我正在使用ApachePOI3.9创建单元格注释 几年来,我一直在使用Erik Pragt在中建议的HSSF表代码,它运行良好 但是,现在我需要向XSSF工作表添加单元格注释 我在同一个页面中尝试了LastNiteCurry建议的代码,效果很好,但它为我创建了透明背景的注释 代码复制如下 protected void setCellComment(Cell cell, String message) { Drawing drawing = cell.getSheet().createDr

我正在使用ApachePOI3.9创建单元格注释

几年来,我一直在使用Erik Pragt在中建议的HSSF表代码,它运行良好

但是,现在我需要向XSSF工作表添加单元格注释

我在同一个页面中尝试了LastNiteCurry建议的代码,效果很好,但它为我创建了透明背景的注释

代码复制如下

protected void setCellComment(Cell cell, String message) {
    Drawing drawing = cell.getSheet().createDrawingPatriarch();
    CreationHelper factory = cell.getSheet().getWorkbook()
            .getCreationHelper();
    // When the comment box is visible, have it show in a 1x3 space
    ClientAnchor anchor = factory.createClientAnchor();
    anchor.setCol1(cell.getColumnIndex());
    anchor.setCol2(cell.getColumnIndex() + 1);
    anchor.setRow1(cell.getRowIndex());
    anchor.setRow2(cell.getRowIndex() + 1);
    anchor.setDx1(100);
    anchor.setDx2(100);
    anchor.setDy1(100);
    anchor.setDy2(100);

    // Create the comment and set the text+author
    Comment comment = drawing.createCellComment(anchor);
    RichTextString str = factory.createRichTextString(message);
    comment.setString(str);
    comment.setAuthor("Apache POI");
    // Assign the comment to the cell
    cell.setCellComment(comment);
}
如何将背景更改为黄色背景


注意:如果在Excel中编辑ApachePOI创建的注释,则该注释将临时显示为黄色背景。但是,如果试图格式化此注释以从Excel中更改背景,则无法。(颜色和线条菜单不显示)

答案是我的Java操作的Excel.xlsm文件的“显示所有注释”设置为true。一旦我更改了此设置,java就正确地创建了注释。

我成功地在包含Button表单控件的工作表中重现了所描述的行为。 我删除了按钮,评论显示正确

作为按钮的替代,我使用本指南从单元格运行宏

我也看到了我插入的带有透明背景的注释,但是是.xls。我正在从头开始创建工作表。我能在POI中做些什么来获得不透明的背景吗?