https://bz.apache.org/bugzilla/show_bug.cgi?id=59393

--- Comment #4 from Javen O'Neal <[email protected]> ---
This would require some restructuring of the way comments are added to a cell.

Right now the order to add a comment is: [1]
1. Create an anchor for the comment (that is, the box that displays the comment
with a yellow-background).
2. Create a comment on the sheet drawing patriarch and set the anchor from step
1
3. Add author and comment string to comment object
4. Assign the comment to a cell in the sheet (prior to this the comment is
parentless).

The problem occurs in step 2, since in order to create the comment, the comment
cell address is needed. The cell address is temporarily set as
CellAddress(anchor.getRow1(), anchor.getCol1()) until it's set again by step 4
above. [2]:
> return XSSFComment(comments, comments.newComment(ref), vmlShape);

The "Multiple cell comments in one cell are not allowed" error that you saw was
POI proactively avoiding a corrupt workbook. Though adding a cell comment to
the drawing without adding it to a cell also produces a corrupt workbook. Any
rewrite will need to address these issues, while considering backwards
compatibility, and hopefully make adding a cell comment easier (such as
Sheet.addCellComment(CellAddress address, String comment[, String author[,
ClientAnchor anchor]])). I'm open to suggestions; patches greatly appreciated.

In the mean time, to fix your problem, you should make row1 and col1 of the
anchor match the address of the cell that will hold the comment before you
create the comment:

    anchor.setRow1(0);
    anchor.setCol1(0);
    Comment comment1 = drawing.createCellComment(anchor);
    RichTextString richTextString1 = helper.createRichTextString("comment1");
    comment1.setString(richTextString1);
    cell1.setCellComment(comment1);

    anchor.setRow1(0);
    anchor.setCol1(1);
    Comment comment2 = drawing.createCellComment(anchor);
    RichTextString richTextString2 = helper.createRichTextString("comment2");
    comment2.setString(richTextString2);
    cell2.setCellComment(comment2);

    anchor.setRow1(0);
    anchor.setCol1(2);
    Comment comment3 = drawing.createCellComment(anchor);
    RichTextString richTextString3 = helper.createRichTextString("comment3");
    comment3.setString(richTextString3);
    cell3.setCellComment(comment3);

[1] https://poi.apache.org/spreadsheet/quick-guide.html#CellComments
[2]
https://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java?revision=1731980&view=markup#l302

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to