You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by fa...@apache.org on 2021/11/20 14:20:49 UTC

svn commit: r1895204 - in /poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf: model/Comments.java model/CommentsTable.java usermodel/XSSFSheet.java

Author: fanningpj
Date: Sat Nov 20 14:20:49 2021
New Revision: 1895204

URL: http://svn.apache.org/viewvc?rev=1895204&view=rev
Log:
add shape data to comments in iterator

Modified:
    poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/model/Comments.java
    poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/model/CommentsTable.java
    poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java

Modified: poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/model/Comments.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/model/Comments.java?rev=1895204&r1=1895203&r2=1895204&view=diff
==============================================================================
--- poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/model/Comments.java (original)
+++ poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/model/Comments.java Sat Nov 20 14:20:49 2021
@@ -72,10 +72,11 @@ public interface Comments {
     Iterator<CellAddress> getCellAddresses();
 
     /**
-     * @return iterator of comments (without their VML Shapes set)
+     * @param sheet the sheet to check for comments
+     * @return iterator of comments
      * @since POI 5.2.0
      */
-    Iterator<XSSFComment> commentIterator();
+    Iterator<XSSFComment> commentIterator(Sheet sheet);
 
     /**
      * Create a new comment and add to the CommentTable.

Modified: poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/model/CommentsTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/model/CommentsTable.java?rev=1895204&r1=1895203&r2=1895204&view=diff
==============================================================================
--- poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/model/CommentsTable.java (original)
+++ poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/model/CommentsTable.java Sat Nov 20 14:20:49 2021
@@ -101,11 +101,13 @@ public class CommentsTable extends POIXM
     }
 
     /**
-     * @return iterator of comments (without their VML Shapes set)
+     * @param sheet the sheet to check for comments
+     * @return iterator of comments
      * @since POI 5.2.0
      */
     @Override
-    public Iterator<XSSFComment> commentIterator() {
+    public Iterator<XSSFComment> commentIterator(Sheet sheet) {
+        XSSFVMLDrawing vml = getVMLDrawing(sheet, false);
         final CommentsTable table = this;
         return new Iterator<XSSFComment>() {
             private final CTComment[] commentsArray = getCTComments().getCommentList().getCommentArray();
@@ -119,7 +121,12 @@ public class CommentsTable extends POIXM
             @Override
             public XSSFComment next() {
                 CTComment ctComment = commentsArray[counter++];
-                return new XSSFComment(table, ctComment, null);
+                CellAddress cellAddress = new CellAddress(ctComment.getRef());
+                CTShape shape = null;
+                if (vml != null) {
+                    shape = vml.findCommentShape(cellAddress.getRow(), cellAddress.getColumn());
+                }
+                return new XSSFComment(table, ctComment, shape);
             }
         };
     }

Modified: poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java?rev=1895204&r1=1895203&r2=1895204&view=diff
==============================================================================
--- poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java (original)
+++ poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java Sat Nov 20 14:20:49 2021
@@ -2956,14 +2956,12 @@ public class XSSFSheet extends POIXMLDoc
      */
     @Override
     public void shiftRows(int startRow, int endRow, final int n, boolean copyRowHeight, boolean resetOriginalRowHeight) {
-        XSSFVMLDrawing vml = getVMLDrawing(false);
-
         int sheetIndex = getWorkbook().getSheetIndex(this);
         String sheetName = getWorkbook().getSheetName(sheetIndex);
         FormulaShifter formulaShifter = FormulaShifter.createForRowShift(
                 sheetIndex, sheetName, startRow, endRow, n, SpreadsheetVersion.EXCEL2007);
-        removeOverwritten(vml, startRow, endRow, n);
-        shiftCommentsAndRows(vml, startRow, endRow, n);
+        removeOverwritten(startRow, endRow, n);
+        shiftCommentsAndRows(startRow, endRow, n);
 
         XSSFRowShifter rowShifter = new XSSFRowShifter(this);
         rowShifter.shiftMergedRegions(startRow, endRow, n);
@@ -3023,7 +3021,8 @@ public class XSSFSheet extends POIXMLDoc
     }
 
     // remove all rows which will be overwritten
-    private void removeOverwritten(XSSFVMLDrawing vml, int startRow, int endRow, final int n) {
+    private void removeOverwritten(int startRow, int endRow, final int n) {
+        XSSFVMLDrawing vml = getVMLDrawing(false);
         HashSet<Integer> rowsToRemoveSet = new HashSet<>();
         for (Iterator<Row> it = rowIterator() ; it.hasNext() ; ) {
             XSSFRow row = (XSSFRow)it.next();
@@ -3052,7 +3051,7 @@ public class XSSFSheet extends POIXMLDoc
 
         // also remove any comments associated with this row
         if (sheetComments != null) {
-            Iterator<XSSFComment> commentIterator = sheetComments.commentIterator();
+            Iterator<XSSFComment> commentIterator = sheetComments.commentIterator(this);
             while (commentIterator.hasNext()) {
                 XSSFComment comment = commentIterator.next();
                 CellAddress ref = comment.getAddress();
@@ -3078,10 +3077,9 @@ public class XSSFSheet extends POIXMLDoc
             }
         }
 
-
     }
 
-    private void shiftCommentsAndRows(XSSFVMLDrawing vml, int startRow, int endRow, final int n){
+    private void shiftCommentsAndRows(int startRow, int endRow, final int n) {
         // then do the actual moving and also adjust comments/rowHeight
         // we need to sort it in a way so the shifting does not mess up the structures,
         // i.e. when shifting down, start from down and go up, when shifting up, vice-versa
@@ -3115,7 +3113,7 @@ public class XSSFSheet extends POIXMLDoc
 
                 // is there a change necessary for the current row?
                 if(newrownum != rownum) {
-                    Iterator<XSSFComment> commentIterator = sheetComments.commentIterator();
+                    Iterator<XSSFComment> commentIterator = sheetComments.commentIterator(this);
                     while (commentIterator.hasNext()) {
                         XSSFComment oldComment = commentIterator.next();
                         CellReference ref = new CellReference(oldComment.getRow(), oldComment.getColumn());
@@ -3123,7 +3121,7 @@ public class XSSFSheet extends POIXMLDoc
                         // is this comment part of the current row?
                         if(ref.getRow() == rownum) {
                             XSSFComment xssfComment = new XSSFComment(sheetComments, oldComment.getCTComment(),
-                                    vml == null ? null : vml.findCommentShape(rownum, ref.getCol()));
+                                    oldComment.getCTShape());
 
                             // we should not perform the shifting right here as we would then find
                             // already shifted comments and would shift them again...
@@ -3200,7 +3198,7 @@ public class XSSFSheet extends POIXMLDoc
 
 
         if (sheetComments != null) {
-            Iterator<XSSFComment> commentIterator = sheetComments.commentIterator();
+            Iterator<XSSFComment> commentIterator = sheetComments.commentIterator(this);
             while (commentIterator.hasNext()) {
                 XSSFComment oldComment = commentIterator.next();
                 CellReference ref = new CellReference(oldComment.getRow(), oldComment.getColumn());



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org