首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用apache-poi自动调整excel注释的大小

使用apache-poi自动调整excel注释的大小
EN

Stack Overflow用户
提问于 2015-01-15 17:58:30
回答 1查看 1.5K关注 0票数 6

我们有很多由apache poi生成的excel报告。其中一些在标题中包含注释。由于有许多报告,我们希望创建通用的解决方案来添加评论。正如我们注意到的,注释可以通过如下代码添加到单元格:

代码语言:javascript
复制
public static void addComment(final Workbook workbook, final Sheet sheet, final Cell cell, final Row row,
        final String comment) {

    final CreationHelper factory = workbook.getCreationHelper();

    final Drawing drawing = sheet.createDrawingPatriarch();

    final ClientAnchor anchor = factory.createClientAnchor();
    anchor.setCol1(cell.getColumnIndex());
    anchor.setCol2(cell.getColumnIndex() + 3);
    anchor.setRow1(row.getRowNum());
    anchor.setRow2(row.getRowNum() + 5);

    final Comment cellComment = drawing.createCellComment(anchor);
    final RichTextString richText = factory.createRichTextString(comment);
    cellComment.setString(richText);
    cell.setCellComment(cellComment);
}

我们还注意到,注释框大小可以通过使用列/行索引来设置-这是我们的主要问题,因为如果第一列有100px,第二列有1000px,那么注释宽度将是1000px。这是我们的问题--有没有可能使用apache poi使用像素而不是列/行索引来设置注释大小?或者,也许有一些方法可以使用apache poi自动计算注释大小?

EN

回答 1

Stack Overflow用户

发布于 2017-06-24 03:22:12

ClientAnchor支持偏移量,至少在具体实现中是这样的:

public XSSFClientAnchor(int dx1, int dy1, int dx2, int dy2, int col1, int row1, int col2, int row2)

dx1是从左偏移,dx2是从右偏移,dy1是从顶部偏移,dy2是从底部偏移(col1,row1是开始行col,col2,row2是结束行col,不包括)。

因此,要减小宽度,只需将一个非零值赋给dx2。

dx1、dx2、dy1和dy2采用英国公制单位。每个EMU有9525个像素,因此您必须使用相当大的值。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27960873

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档