Bug 63166 - after using createCellComment to create comment for A1 cell first, cannot create comment for other cell any more.
Summary: after using createCellComment to create comment for A1 cell first, cannot cre...
Status: NEW
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: unspecified
Hardware: PC Mac OS X 10.1
: P2 major (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-02-11 05:25 UTC by Tony
Modified: 2019-02-11 05:25 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tony 2019-02-11 05:25:09 UTC
After using createCellComment to create comment for A1 cell first, cannot create comment for other cell any more. 

I have checked the source code in XSSFDrawing.java, it will always use  A1(row1,col1) to check if there is any comment in the cell. I think this is the root cause for the issue

CellAddress ref = new CellAddress(ca.getRow1(), ca.getCol1());

----
Drawing drawing = sheet.createDrawingPatriarch();
 ClientAnchor anchor = createHelper.createClientAnchor();
 Comment comment = drawing.createCellComment(anchor);
 comment.setString(createHelper.createRichTextString(commentText));
----

XSSFDrawing.java:

 public XSSFComment createCellComment(ClientAnchor anchor) {
        XSSFClientAnchor ca = (XSSFClientAnchor)anchor;
        XSSFSheet sheet = this.getSheet();
        CommentsTable comments = sheet.getCommentsTable(true);
        XSSFVMLDrawing vml = sheet.getVMLDrawing(true);
        com.microsoft.schemas.vml.CTShape vmlShape = vml.newCommentShape();
        if (ca.isSet()) {
            int dx1Pixels = ca.getDx1() / 9525;
            int dy1Pixels = ca.getDy1() / 9525;
            int dx2Pixels = ca.getDx2() / 9525;
            int dy2Pixels = ca.getDy2() / 9525;
            String position = ca.getCol1() + ", " + dx1Pixels + ", " + ca.getRow1() + ", " + dy1Pixels + ", " + ca.getCol2() + ", " + dx2Pixels + ", " + ca.getRow2() + ", " + dy2Pixels;
            vmlShape.getClientDataArray(0).setAnchorArray(0, position);
        }

        CellAddress ref = new CellAddress(ca.getRow1(), ca.getCol1());
        if (comments.findCellComment(ref) != null) {
            throw new IllegalArgumentException("Multiple cell comments in one cell are not allowed, cell: " + ref);
        } else {
            return new XSSFComment(comments, comments.newComment(ref), vmlShape);
        }
    }




java.lang.IllegalArgumentException: Multiple cell comments in one cell are not allowed, cell: A1

	at org.apache.poi.xssf.usermodel.XSSFDrawing.createCellComment(XSSFDrawing.java:398)
	at org.apache.poi.xssf.streaming.SXSSFDrawing.createCellComment(SXSSFDrawing.java:52)