1

我正在尝试将 CellComment 复制到新单元格(使用 Apache POI)。我知道我必须创建新评论(而不是将旧评论设置到新单元格中),但我似乎无法找出如何复制 Anchor。

private void createComment(Cell aNewCell, Comment theOldComment) {
    CreationHelper createHelper = aNewCell.getSheet().getWorkbook().getCreationHelper();
    ClientAnchor anchor = createHelper.createClientAnchor();
    // How to get the old CellComment anchor for x1, c2, y1, y2???
    Drawing drawing = aNewCell.getSheet().createDrawingPatriarch();
    Comment aNewComment = drawing.createCellComment(anchor);
    aNewComment.setString(theOldComment.getString());
    aNewCell.setCellComment(aNewComment);
}
4

1 回答 1

0

使用族长而不是CreationHelper. 从 的对象创建 AnchorHSSFPatriarch并将值作为参数传递给createAnchor函数。希望这可以帮助。

 HSSFPatriarch drawing = sheet.createDrawingPatriarch();
 ClientAnchor anchor = drawing.createAnchor(10, 20, 30, 40, (short)4, 2, (short)6, 5);

希望这可以帮助。

 private void createComment(HSSFCell aNewCell, Comment theOldComment) {
        HSSFPatriarch drawing = aNewCell.getSheet().getDrawingPatriarch();
        ClientAnchor anchor = drawing.createAnchor(drawing.getChildren().get(0).getAnchor().getDx1(),
                drawing.getChildren().get(0).getAnchor().getDx2(), drawing.getChildren().get(0).getAnchor().getDy1(),
                drawing.getChildren().get(0).getAnchor().getDy2(), (short)4, 2, (short)6, 5);
        Comment aNewComment = drawing.createCellComment(anchor);
        aNewComment.setString(theOldComment.getString());
        aNewCell.setCellComment(aNewComment);
    }
于 2013-07-19T20:00:44.367 回答