我们有很多由apache poi生成的excel报告。其中一些在标题中包含注释。由于有许多报告,我们希望创建通用的解决方案来添加评论。正如我们注意到的,注释可以通过如下代码添加到单元格:
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自动计算注释大小?
发布于 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个像素,因此您必须使用相当大的值。
https://stackoverflow.com/questions/27960873
复制相似问题