Setting Comments in Excel (with apache poi)

1.2k views Asked by At

I'm trying to set cell comments to a set of cells, and for the ones that are on the right of the page, the comments have the proper size, but for the others that are on a previous column of the page, their size begin to descrease with no appearent explanation (for me).

Screenshots of the situation:

  1. Comment with the correct size http://prntscr.com/7ez65x

  2. Starting to became narrower http://prntscr.com/7ez6bm

And for the ones that are on previous columns, the comments don't have width at all... like they have collapsed on themselves.

The code that i'm using to generate the comments is:

protected void setCellComment(Cell cell, String message)
{
    Drawing drawing = cell.getSheet().createDrawingPatriarch();
    CreationHelper factory = cell.getSheet().getWorkbook().getCreationHelper();

    ClientAnchor anchor = factory.createClientAnchor();

    int width = 3;
    int height = 2;
    anchor.setCol1(cell.getColumnIndex());
    anchor.setCol2(cell.getColumnIndex() + width);
    anchor.setRow1(cell.getRowIndex());
    anchor.setRow2(cell.getRowIndex() + height);
    anchor.setDx1(100);
    anchor.setDx2(100);
    anchor.setDy1(100);
    anchor.setDy2(100);

    Comment comment = drawing.createCellComment(anchor);
    RichTextString str = factory.createRichTextString(message);
    comment.setString(str);

    cell.setCellComment(comment);
}

Please Help!

Thanks a lot

1

There are 1 answers

0
Samuel Malicett Campos On BEST ANSWER

I solved the problem removing the freezing panes that the sheet had. Probably there is a bug with the combination between freezing panes and comments.