Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating cell comments in apache poi (for .xlsx files) with show comments disabled

I am trying to create cells comments using apache poi. I am able to create the comments, but by default they are always displayed in excel. I have to manual right click on the cell and un-tick show comments to make them invisible(now they appear only when I hover on the cell). Is it possible to make cell comments invisible by default(so that they don't appear in the excel until user hover over the cell.)

Here is the code I used :

    Drawing drawing = cell.getSheet().createDrawingPatriarch();
    CreationHelper factory = cell.getSheet().getWorkbook().getCreationHelper();
    ClientAnchor anchor = factory.createClientAnchor();
    anchor.setCol1(cell.getColumnIndex());
    anchor.setCol2(cell.getColumnIndex() + 1);
    anchor.setRow1(cell.getRowIndex());
    anchor.setRow2(cell.getRowIndex() + 3);

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

    cell.setCellComment(comment);
like image 661
Paroksh Saxena Avatar asked Apr 19 '13 07:04

Paroksh Saxena


1 Answers

Paroksh. I have executed same code that you have given. By default, I am getting comments on hover only. It seems that it is not the code issue but the Excel settings issue. I have checked it in excel 2010. If you have different version then check the similar settings.

Please check Home --> Option --> Advanced --> Display...

there "Indicators only, and comments on hover" radio button should be selected.

like image 143
Sankumarsingh Avatar answered Sep 16 '22 11:09

Sankumarsingh