@@ -, +, @@ Proposed fix for Bug 54920: do not set column and row separatedely, but use a reference for newComment() --- a/src/ooxml/java/org/apache/poi/xssf/model/CommentsTable.java +++ a/src/ooxml/java/org/apache/poi/xssf/model/CommentsTable.java @@ -126,9 +126,9 @@ public class CommentsTable extends POIXMLDocumentPart { return commentRefs.get(cellRef); } - public CTComment newComment() { + public CTComment newComment(String ref) { CTComment ct = comments.getCommentList().addNewComment(); - ct.setRef("A1"); + ct.setRef(ref); ct.setAuthorId(0); if(commentRefs != null) { --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java +++ a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java @@ -33,6 +33,7 @@ import org.apache.poi.openxml4j.opc.PackageRelationship; import org.apache.poi.openxml4j.opc.TargetMode; import org.apache.poi.ss.usermodel.ClientAnchor; import org.apache.poi.ss.usermodel.Drawing; +import org.apache.poi.ss.util.CellReference; import org.apache.poi.util.Internal; import org.apache.poi.xssf.model.CommentsTable; import org.apache.xmlbeans.XmlCursor; @@ -298,9 +299,10 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing { ca.getCol2() + ", 0, " + ca.getRow2() + ", 0"; vmlShape.getClientDataArray(0).setAnchorArray(0, position); } - XSSFComment shape = new XSSFComment(comments, comments.newComment(), vmlShape); - shape.setColumn(ca.getCol1()); - shape.setRow(ca.getRow1()); + String ref = new CellReference(ca.getRow1(), ca.getCol1()).formatAsString(); + XSSFComment shape = new XSSFComment(comments, comments.newComment(ref), vmlShape); +// shape.setColumn(ca.getCol1()); +// shape.setRow(ca.getRow1()); return shape; } --- a/src/ooxml/testcases/org/apache/poi/xssf/model/TestCommentsTable.java +++ a/src/ooxml/testcases/org/apache/poi/xssf/model/TestCommentsTable.java @@ -187,12 +187,12 @@ public class TestCommentsTable extends TestCase { public void testRemoveComment() throws Exception { CommentsTable sheetComments = new CommentsTable(); - CTComment a1 = sheetComments.newComment(); - a1.setRef("A1"); - CTComment a2 = sheetComments.newComment(); - a2.setRef("A2"); - CTComment a3 = sheetComments.newComment(); - a3.setRef("A3"); + CTComment a1 = sheetComments.newComment("A1"); +// a1.setRef("A1"); + CTComment a2 = sheetComments.newComment("A2"); +// a2.setRef("A2"); + CTComment a3 = sheetComments.newComment("A3"); +// a3.setRef("A3"); assertSame(a1, sheetComments.getCTComment("A1")); assertSame(a2, sheetComments.getCTComment("A2")); --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFComment.java +++ a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFComment.java @@ -50,7 +50,7 @@ public final class TestXSSFComment extends BaseTestCellComment { assertEquals(1, sheetComments.getCTComments().getAuthors().sizeOfAuthorArray()); assertEquals(1, sheetComments.getNumberOfAuthors()); - CTComment ctComment = sheetComments.newComment(); + CTComment ctComment = sheetComments.newComment("A1"); CTShape vmlShape = CTShape.Factory.newInstance(); XSSFComment comment = new XSSFComment(sheetComments, ctComment, vmlShape); @@ -64,7 +64,7 @@ public final class TestXSSFComment extends BaseTestCellComment { public void testGetSetCol() { CommentsTable sheetComments = new CommentsTable(); XSSFVMLDrawing vml = new XSSFVMLDrawing(); - CTComment ctComment = sheetComments.newComment(); + CTComment ctComment = sheetComments.newComment("A1"); CTShape vmlShape = vml.newCommentShape(); XSSFComment comment = new XSSFComment(sheetComments, ctComment, vmlShape); @@ -82,7 +82,7 @@ public final class TestXSSFComment extends BaseTestCellComment { public void testGetSetRow() { CommentsTable sheetComments = new CommentsTable(); XSSFVMLDrawing vml = new XSSFVMLDrawing(); - CTComment ctComment = sheetComments.newComment(); + CTComment ctComment = sheetComments.newComment("A1"); CTShape vmlShape = vml.newCommentShape(); XSSFComment comment = new XSSFComment(sheetComments, ctComment, vmlShape); @@ -150,7 +150,7 @@ public final class TestXSSFComment extends BaseTestCellComment { public void testAuthor() { CommentsTable sheetComments = new CommentsTable(); - CTComment ctComment = sheetComments.newComment(); + CTComment ctComment = sheetComments.newComment("A1"); assertEquals(1, sheetComments.getNumberOfAuthors()); XSSFComment comment = new XSSFComment(sheetComments, ctComment, null);