You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ce...@apache.org on 2016/05/29 21:33:48 UTC

svn commit: r1746062 - in /poi/trunk: src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFComment.java test-data/spreadsheet/57838.xlsx

Author: centic
Date: Sun May 29 21:33:47 2016
New Revision: 1746062

URL: http://svn.apache.org/viewvc?rev=1746062&view=rev
Log:
Bug 57838: Also remove comments when removing a row

Added:
    poi/trunk/test-data/spreadsheet/57838.xlsx
Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFComment.java

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java?rev=1746062&r1=1746061&r2=1746062&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java Sun May 29 21:33:47 2016
@@ -409,7 +409,6 @@ public class XSSFSheet extends POIXMLDoc
     /**
      * Verify that none of the merged regions intersect a multi-cell array formula in this sheet
      *
-     * @param region
      * @throws IllegalStateException if candidate region intersects an existing array formula in this sheet
      */
     private void checkForMergedRegionsIntersectingArrayFormulas() {
@@ -1386,8 +1385,8 @@ public class XSSFSheet extends POIXMLDoc
      * Rows between startRow and endRow that haven't been created are not included
      * in result unless createRowIfMissing is true
      *
-     * @param startRow the first row number in this sheet to return
-     * @param endRow the last row number in this sheet to return
+     * @param startRowNum the first row number in this sheet to return
+     * @param endRowNum the last row number in this sheet to return
      * @param createRowIfMissing
      * @return All rows between startRow and endRow, inclusive
      * @throws IllegalArgumentException if startRowNum and endRowNum are not in ascending order
@@ -1880,6 +1879,15 @@ public class XSSFSheet extends POIXMLDoc
         int idx = _rows.headMap(row.getRowNum()).size();
         _rows.remove(row.getRowNum());
         worksheet.getSheetData().removeRow(idx);
+
+        // also remove any comment located in that row
+        if(sheetComments != null) {
+            for (CellAddress ref : getCellComments().keySet()) {
+                if (ref.getRow() == idx) {
+                    sheetComments.removeComment(ref);
+                }
+            }
+        }
     }
 
     /**

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFComment.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFComment.java?rev=1746062&r1=1746061&r2=1746062&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFComment.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFComment.java Sun May 29 21:33:47 2016
@@ -18,14 +18,9 @@
 package org.apache.poi.xssf.usermodel;
 
 import static org.apache.poi.xssf.usermodel.XSSFRelation.NS_SPREADSHEETML;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.fail;
-
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
+import static org.junit.Assert.*;
+
+import java.io.*;
 
 import org.apache.poi.hssf.usermodel.HSSFRichTextString;
 import org.apache.poi.ss.usermodel.BaseTestCellComment;
@@ -314,4 +309,28 @@ public final class TestXSSFComment exten
             wb.close();
         }
     }
+
+    @Test
+    public void bug57838DeleteRowsWthCommentsBug() throws IOException {
+        Workbook wb = XSSFTestDataSamples.openSampleWorkbook("57838.xlsx");
+        Sheet sheet=wb.getSheetAt(0);
+        Comment comment1 = sheet.getCellComment(new CellAddress(2, 1));
+        assertNotNull(comment1);
+        Comment comment2 = sheet.getCellComment(new CellAddress(2, 2));
+        assertNotNull(comment2);
+        Row row=sheet.getRow(2);
+        assertNotNull(row);
+
+        sheet.removeRow(row); // Remove row from index 2
+
+        row=sheet.getRow(2);
+        assertNull(row); // Row is null since we deleted it.
+
+        comment1 = sheet.getCellComment(new CellAddress(2, 1));
+        assertNull(comment1); // comment should be null but will fail due to bug
+        comment2 = sheet.getCellComment(new CellAddress(2, 2));
+        assertNull(comment2); // comment should be null but will fail due to bug
+
+        wb.close();
+    }
 }

Added: poi/trunk/test-data/spreadsheet/57838.xlsx
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/57838.xlsx?rev=1746062&view=auto
==============================================================================
Binary files poi/trunk/test-data/spreadsheet/57838.xlsx (added) and poi/trunk/test-data/spreadsheet/57838.xlsx Sun May 29 21:33:47 2016 differ



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