在 apache poi 中使用 HSSFClientAnchor 创建单元格注释 [英] creating cell comments using HSSFClientAnchor in apache poi

查看:89
本文介绍了在 apache poi 中使用 HSSFClientAnchor 创建单元格注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以向我解释如何在创建单元格评论时正确使用锚点吗?我的正在工作,但电子表格发生了变化,我在显示单元格注释时遇到了问题.这是我使用的有效代码:

Could someone please explain to me how to properly use the Anchors when creating cell comments? Mine were working, but the spread sheet changed and I am having issues getting my cell comments to appear. This is the code I was using that worked:

 Comment c = drawing.createCellComment (new HSSFClientAnchor(0, 0, 0, 0, (short)4, 2, (short)6, 5));

这主要是通过实验发现的.查看它的 api 并不能让它变得更清楚.

That was found mostly by experimenting around. Looking at the api for it doesn't exactly make it any clearer.

根据快速入门指南,我也尝试了以下方法但没有成功:

Based on the quick start guide I have also tried the following with no luck:

ClientAnchor anchor = chf.createClientAnchor();
Comment c = drawing.createCellComment(anchor);
c.setString(chf.createRichTextString(message)); 

推荐答案

有点晚了,但这可能会起作用(它对我有用,而快速入门中的 Apache POI 示例也对我不起作用):

A bit late, but this will probably work (it works for me, while the Apache POI example from the quick start also didn't work for me):

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

埃里克·普拉格特

这篇关于在 apache poi 中使用 HSSFClientAnchor 创建单元格注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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