]> source.dussan.org Git - poi.git/commitdiff
try to make comments table more extensible
authorPJ Fanning <fanningpj@apache.org>
Wed, 17 Nov 2021 23:04:26 +0000 (23:04 +0000)
committerPJ Fanning <fanningpj@apache.org>
Wed, 17 Nov 2021 23:04:26 +0000 (23:04 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1895127 13f79535-47bb-0310-9956-ffa450edef68

poi-ooxml/src/main/java/org/apache/poi/xssf/model/CommentsTable.java
poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFVMLDrawing.java

index 9ce61fbfb0b1e8a128ec2f1a4439906d9a670467..bb7b65082bd86e118743564ccbd70e391786673e 100644 (file)
@@ -24,6 +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;
@@ -286,6 +287,29 @@ public class CommentsTable extends POIXMLDocumentPart implements Comments {
         return false;
     }
 
+    /**
+     * 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
      *
index e96a5e09332b68bfd6483d7090e1209e466f3c34..d9b43318858289142a3709040d4643a68d334b3a 100644 (file)
@@ -3052,17 +3052,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet  {
 
         // also remove any comments associated with this row
         if (sheetComments != null) {
-            CTCommentList lst = sheetComments.getCTComments().getCommentList();
-            for (CTComment comment : lst.getCommentArray()) {
-                String strRef = comment.getRef();
-                CellAddress ref = new CellAddress(strRef);
-
-                // is this comment part of the current row?
-                if(rowsToRemoveSet.contains(ref.getRow())) {
-                    sheetComments.removeComment(ref);
-                    vml.removeCommentShape(ref.getRow(), ref.getColumn());
-                }
-            }
+            sheetComments.removeCommentsFromRows(this, rowsToRemoveSet);
         }
 
         // also remove any hyperlinks associated with this row
index 640534354a2dd1f9acb8c068e3dcb77e864ecfba..e09504c725111192fe23a003ebce5817a711edaf 100644 (file)
@@ -314,7 +314,11 @@ public final class XSSFVMLDrawing extends POIXMLDocumentPart {
         return (crow == row && ccol == col);
     }
 
-    protected boolean removeCommentShape(int row, int col){
+    /**
+     * Internal use only
+     */
+    @Internal
+    public boolean removeCommentShape(int row, int col){
         XmlCursor cur = root.getXml().newCursor();
         for (boolean found = cur.toFirstChild(); found; found = cur.toNextSibling()) {
             XmlObject itm = cur.getObject();