gpt4 book ai didi

java - 使用 Apache POI 创建的单元格评论具有透明背景

转载 作者:行者123 更新时间:2023-11-29 08:46:02 25 4
gpt4 key购买 nike

我正在使用 Apache POI 3.9 创建单元格评论。

我一直在使用 Erik Pragt 在 creating cell comments using HSSFClientAnchor in apache poi 中建议的 HSSF 表代码用了几年,效果很好。

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

我已经在同一页面中尝试了 lastnitescurry 建议的代码,效果很好,但它为我创建了具有透明背景的评论。

代码转载如下。

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 创建的评论,那么它会暂时显示为黄色背景。但是,如果有人试图格式化此评论以从 Excel 中更改背景,则不能。 (颜色和线条菜单没有出现)

最佳答案

答案是我的 Java 正在处理一个将“显示所有评论”设置为 true 的 Excel .xlsm 文件。一旦我改变了这个设置,java 就正确地创建了评论。

关于java - 使用 Apache POI 创建的单元格评论具有透明背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25311302/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com