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/17 23:26:31 UTC

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

Author: fanningpj
Date: Wed Nov 17 23:26:31 2021
New Revision: 1895128

URL: http://svn.apache.org/viewvc?rev=1895128&view=rev
Log:
try to make comments table more extensible

Modified:
    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
    poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFVMLDrawing.java

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=1895128&r1=1895127&r2=1895128&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 Wed Nov 17 23:26:31 2021
@@ -24,9 +24,7 @@ import java.io.OutputStream;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
-import java.util.Set;
 
-import com.microsoft.schemas.vml.CTShape;
 import org.apache.poi.ooxml.POIXMLDocumentPart;
 import org.apache.poi.openxml4j.opc.PackagePart;
 import org.apache.poi.ss.util.CellAddress;
@@ -97,6 +95,29 @@ public class CommentsTable extends POIXM
         writeTo(out);
         out.close();
     }
+
+    /**
+     * @return iterator of comments
+     * @since POI 5.2.0
+     */
+    public Iterator<XSSFComment> commentIterator() {
+        final CommentsTable table = this;
+        return new Iterator<XSSFComment>() {
+            private final CTComment[] commentsArray = getCTComments().getCommentList().getCommentArray();
+            private int counter = 0;
+
+            @Override
+            public boolean hasNext() {
+                return counter < commentsArray.length;
+            }
+
+            @Override
+            public XSSFComment next() {
+                CTComment ctComment = commentsArray[counter++];
+                return new XSSFComment(table, ctComment, null);
+            }
+        };
+    }
     
     /**
      * Called after the reference is updated, so that
@@ -288,29 +309,6 @@ public class CommentsTable extends POIXM
     }
 
     /**
-     * Remove the comment at cellRef location, if one exists
-     *
-     * @param rowNums the rows for which all comments will be removed
-     * @since POI 5.2.0
-     */
-    public void removeCommentsFromRows(XSSFSheet sheet, Set<Integer> rowNums) {
-        CTCommentList lst = getCTComments().getCommentList();
-        XSSFVMLDrawing vml = sheet.getVMLDrawing(false);
-        for (CTComment comment : lst.getCommentArray()) {
-            String strRef = comment.getRef();
-            CellAddress ref = new CellAddress(strRef);
-
-            // is this comment part of the current row?
-            if(rowNums.contains(ref.getRow())) {
-                removeComment(ref);
-                if (vml != null) {
-                    vml.removeCommentShape(ref.getRow(), ref.getColumn());
-                }
-            }
-        }
-    }
-
-    /**
      * Returns the underlying CTComments list xmlbean
      *
      * @return underlying comments list xmlbean

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=1895128&r1=1895127&r2=1895128&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 Wed Nov 17 23:26:31 2021
@@ -3052,7 +3052,20 @@ public class XSSFSheet extends POIXMLDoc
 
         // also remove any comments associated with this row
         if (sheetComments != null) {
-            sheetComments.removeCommentsFromRows(this, rowsToRemoveSet);
+            Iterator<XSSFComment> commentIterator = sheetComments.commentIterator();
+            while (commentIterator.hasNext()) {
+                XSSFComment comment = commentIterator.next();
+                CellAddress ref = comment.getAddress();
+
+                // is this comment part of the current row?
+                if(rowsToRemoveSet.contains(ref.getRow())) {
+                    sheetComments.removeComment(ref);
+                    if (vml != null) {
+                        vml.removeCommentShape(ref.getRow(), ref.getColumn());
+                    }
+                }
+
+            }
         }
 
         // also remove any hyperlinks associated with this row

Modified: poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFVMLDrawing.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFVMLDrawing.java?rev=1895128&r1=1895127&r2=1895128&view=diff
==============================================================================
--- poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFVMLDrawing.java (original)
+++ poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFVMLDrawing.java Wed Nov 17 23:26:31 2021
@@ -314,11 +314,7 @@ public final class XSSFVMLDrawing extend
         return (crow == row && ccol == col);
     }
 
-    /**
-     * Internal use only
-     */
-    @Internal
-    public boolean removeCommentShape(int row, int col){
+    protected boolean removeCommentShape(int row, int col){
         XmlCursor cur = root.getXml().newCursor();
         for (boolean found = cur.toFirstChild(); found; found = cur.toNextSibling()) {
             XmlObject itm = cur.getObject();



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