有人可以在创建单元格注释时向我解释如何正确使用Anchors吗?我的工作正在进行,但电子表格发生了变化,我在查看单元格注释时出现问题.这是我使用的代码:
Comment c = drawing.createCellComment (new HSSFClientAnchor(0, 0, 0, 0, (short)4, 2, (short)6, 5));
Run Code Online (Sandbox Code Playgroud)
这主要是通过试验来找到的.看看它的api并没有让它更清楚.
根据快速入门指南,我也试过以下没有运气:
ClientAnchor anchor = chf.createClientAnchor();
Comment c = drawing.createCellComment(anchor);
c.setString(chf.createRichTextString(message));
Run Code Online (Sandbox Code Playgroud)
有点晚了,但这可能会起作用(它适用于我,而快速启动的Apache POI示例对我来说也不起作用):
public void setComment(String text, Cell cell) {
final Map<Sheet, HSSFPatriarch> drawingPatriarches = new HashMap<Sheet, HSSFPatriarch>();
CreationHelper createHelper = cell.getSheet().getWorkbook().getCreationHelper();
HSSFSheet sheet = (HSSFSheet) cell.getSheet();
HSSFPatriarch drawingPatriarch = drawingPatriarches.get(sheet);
if (drawingPatriarch == null) {
drawingPatriarch = sheet.createDrawingPatriarch();
drawingPatriarches.put(sheet, drawingPatriarch);
}
Comment comment = drawingPatriarch.createComment(new HSSFClientAnchor(0, 0, 0, 0, (short) 4, 2, (short) 6, 5));
comment.setString(createHelper.createRichTextString(text));
cell.setCellComment(comment);
}
Run Code Online (Sandbox Code Playgroud)
埃里克·格拉特
| 归档时间: |
|
| 查看次数: |
8886 次 |
| 最近记录: |