From e65f235198d69e1b387ecff5e7956ca1ee514910 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Wed, 17 Nov 2021 23:35:16 +0000 Subject: [PATCH] try to make comments table more extensible git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1895129 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/xssf/model/CommentsTable.java | 2 +- .../apache/poi/xssf/usermodel/XSSFSheet.java | 22 +++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/model/CommentsTable.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/model/CommentsTable.java index f0ab8deb61..876028a579 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/model/CommentsTable.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/model/CommentsTable.java @@ -97,7 +97,7 @@ public class CommentsTable extends POIXMLDocumentPart implements Comments { } /** - * @return iterator of comments + * @return iterator of comments (without their VML Shapes set) * @since POI 5.2.0 */ public Iterator commentIterator() { diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java index 11fc454a24..504324cdb2 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java @@ -3115,14 +3115,14 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { // is there a change necessary for the current row? if(newrownum != rownum) { - CTCommentList lst = sheetComments.getCTComments().getCommentList(); - for (CTComment comment : lst.getCommentArray()) { - String oldRef = comment.getRef(); - CellReference ref = new CellReference(oldRef); + Iterator commentIterator = sheetComments.commentIterator(); + while (commentIterator.hasNext()) { + XSSFComment oldComment = commentIterator.next(); + CellReference ref = new CellReference(oldComment.getRow(), oldComment.getColumn()); // is this comment part of the current row? if(ref.getRow() == rownum) { - XSSFComment xssfComment = new XSSFComment(sheetComments, comment, + XSSFComment xssfComment = new XSSFComment(sheetComments, oldComment.getCTComment(), vml == null ? null : vml.findCommentShape(rownum, ref.getCol())); // we should not perform the shifting right here as we would then find @@ -3199,16 +3199,16 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { }); - if(sheetComments != null){ - CTCommentList lst = sheetComments.getCTComments().getCommentList(); - for (CTComment comment : lst.getCommentArray()) { - String oldRef = comment.getRef(); - CellReference ref = new CellReference(oldRef); + if (sheetComments != null) { + Iterator commentIterator = sheetComments.commentIterator(); + while (commentIterator.hasNext()) { + XSSFComment oldComment = commentIterator.next(); + CellReference ref = new CellReference(oldComment.getRow(), oldComment.getColumn()); int columnIndex =ref.getCol(); int newColumnIndex = shiftedRowNum(startColumnIndex, endColumnIndex, n, columnIndex); if(newColumnIndex != columnIndex){ - XSSFComment xssfComment = new XSSFComment(sheetComments, comment, + XSSFComment xssfComment = new XSSFComment(sheetComments, oldComment.getCTComment(), vml == null ? null : vml.findCommentShape(ref.getRow(), columnIndex)); commentsToShift.put(xssfComment, newColumnIndex); } -- 2.39.5