使用Apache POI创build的单元格注释具有透明背景

我正在使用Apache POI 3.9创build单元格注释。

我已经使用Erik Pragtbuild议的HSSF表单的代码在Apache poi中使用HSSFClientAnchor创build单元格注释几年,它运行良好。

不过,现在我需要将单元格注释添加到XSSF表单中。

我已经尝试了在同一页面上使用lastnitescurrybuild议的代码,这很好地工作,但它为我创build了一个透明背景的评论。

代码转载如下。

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中编辑apache-poi创build的注释,则会暂时显示黄色背景。 但是,如果试图将此注释格式化为在Excel中更改背景,则不能。 (“颜色和线条”菜单不出现)

答案是我的Java正在操纵一个Excel的.xlsm文件“显示所有评论”设置为true。 一旦我改变了这个设置,java就创build了正确的注释。