when set comment for Multiple cell included cell "A1", always got a Exception: java.lang.IllegalArgumentException: Multiple cell comments in one cell are not allowed, cell: A1 if don't set comment for cell "A1", Exception will not happen. if only set comment for cell "A1", Exception will not happen.
Can you share some of your code, ideally as self-sufficient unit-test that allows others to reproduce the problem? This will make it much easier for other to take a look. If you are able we also gladly accept patch-submissions if you can figure out where it fails in Apache POI.
Created attachment 33825 [details] Code to reappear the bug.
(In reply to Dominik Stadler from comment #1) > Can you share some of your code, ideally as self-sufficient unit-test that > allows others to reproduce the problem? This will make it much easier for > other to take a look. > > If you are able we also gladly accept patch-submissions if you can figure > out where it fails in Apache POI. I made a test cases as (attachment 33825 [details] ) to reproduce the problem.
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
Added disabled unit test in r1742868.