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

隐身守侯 提交于 2019-12-07 01:07:29

问题


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);

回答1:


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.



来源:https://stackoverflow.com/questions/16099912/creating-cell-comments-in-apache-poi-for-xlsx-files-with-show-comments-disabl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!