Bug 59388

Summary: setComment with option isVisible
Product: POI Reporter: ORLANDI <orlandi.m70>
Component: XSSFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: normal CC: arieh.kellermann
Priority: P2    
Version: 3.14-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: All   
Attachments: In the attachment a xlsx file with two cells and one of them created by POI.

Description ORLANDI 2016-04-27 14:31:52 UTC
Created attachment 33812 [details]
In the attachment a xlsx file with two cells and one of them created by POI.

I insert a comment on a cell and set its visibile property to true value (by coding with POI). Then I open the file and see the dialog whith comment up. But if I just drag or click on the cell which contains the comment, the dialog disappears and therefore having a different behaviour respect to setting visible property to true by using menu.
Comment 1 Javen O'Neal 2016-04-27 14:43:30 UTC
Could you unzip the OOXML file and diff the Excel-created comment and POI-created comment? This should be the first step to determining what POI is doing incorrectly.
Comment 2 ORLANDI 2016-04-27 15:45:13 UTC
POI created OOXML:
<?xml version="1.0" encoding="UTF-8"?>
<comments xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><authors><author/></authors><commentList><comment ref="B2" authorId="0"><text><t>Commento visibile</t></text></comment></commentList></comments>


EXCEL created OOXML:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<comments xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><authors><author>Author</author></authors><commentList><comment ref="B2" authorId="0"><text><r><rPr><b/><sz val="9"/><color indexed="81"/><rFont val="Tahoma"/><charset val="1"/></rPr><t>Author:</t></r><r><rPr><sz val="9"/><color indexed="81"/><rFont val="Tahoma"/><charset val="1"/></rPr><t xml:space="preserve">
commento visibile</t></r></text></comment></commentList></comments>


Actuaally they look really different. I cannot find any property to set other additional attribute.
Comment 3 ORLANDI 2016-04-27 16:04:06 UTC
(In reply to Javen O'Neal from comment #1)
> Could you unzip the OOXML file and diff the Excel-created comment and
> POI-created comment? This should be the first step to determining what POI
> is doing incorrectly.

POI created OOXML:
<?xml version="1.0" encoding="UTF-8"?>
<comments xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><authors><author/></authors><commentList><comment ref="B2" authorId="0"><text><t>Commento visibile</t></text></comment></commentList></comments>


EXCEL created OOXML:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<comments xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><authors><author>Author</author></authors><commentList><comment ref="B2" authorId="0"><text><r><rPr><b/><sz val="9"/><color indexed="81"/><rFont val="Tahoma"/><charset val="1"/></rPr><t>Author:</t></r><r><rPr><sz val="9"/><color indexed="81"/><rFont val="Tahoma"/><charset val="1"/></rPr><t xml:space="preserve">
commento visibile</t></r></text></comment></commentList></comments>


Actuaally they look really different. I cannot find any property to set other additional attribute.
Comment 4 ORLANDI 2016-05-05 10:09:03 UTC
Hi,

comparing two XML files, a POI-generated one and an Excel-generated one, it seems that the different behaviour is due to the \xl\drawingsvmlDrawing1.vml file. The Excel-generated one has an additional line apparently specifying the visibility, <x:Visible/>:

<!-- ... -->
<x:ClientData ObjectType="Note">
      <x:MoveWithCells/>
      <x:SizeWithCells/>
      <x:Anchor>10, 0, 10, 0, 11, 0, 13, 0</x:Anchor>
      <x:AutoFill>False</x:AutoFill>
      <x:Row>0</x:Row>
      <x:Column>0</x:Column>
      <x:Visible/>
   </x:ClientData> 
<!-- ... -->

If I unzip the POI-generated file, I add that line in the drawingsvmlDrawing1.vml file and then I open the file again, the comment visibility behaviour is preserved as expected.

Thank you.
Comment 5 Dominik Stadler 2016-05-19 19:01:51 UTC
Can you post some sample-code how you populate the comment? 

The class XSSFVMLDrawing allows access to the low-level API CTShape and CTClientData which encapsulates the "visible" attribute.
Comment 6 ORLANDI 2016-05-25 10:19:43 UTC
Here's the code:

/* ... */

XSSFWorkbook w = new XSSFWorkbook();
w.createSheet();

Comment commentToInsert = null;

ClientAnchor anchorForComment = w.getCreationHelper().createClientAnchor();
anchorForComment.setAnchorType(3);
anchorForComment.setCol1(1);
anchorForComment.setCol2(4);
anchorForComment.setRow1(1);
anchorForComment.setRow2(4);
anchorForComment.setDx1(100);
anchorForComment.setDx2(400);
anchorForComment.setDy1(100);
anchorForComment.setDy2(400);

Drawing drawingForComments = w.getSheetAt(0).createDrawingPatriarch();
commentToInsert = drawingForComments.createCellComment(anchorForComment);
commentToInsert.setString(w.getCreationHelper().createRichTextString("Hi!"));

w.getSheetAt(0).createRow(0).createCell(0).setCellComment(commentToInsert);

//Setting cell comment visibility
w.getSheetAt(0).getRow(0).getCell(0).getCellComment().setVisible(true);

/* ... */
Comment 7 Dominik Stadler 2021-06-16 20:17:37 UTC
A proposed fix is available as PR at https://github.com/apache/poi/pull/236
Comment 8 PJ Fanning 2021-10-18 10:49:05 UTC
https://github.com/apache/poi/pull/239 is now merged