aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominik Stadler <centic@apache.org>2016-05-29 21:33:47 +0000
committerDominik Stadler <centic@apache.org>2016-05-29 21:33:47 +0000
commit0fdbc396e456b99200a968e076be86ae95b2188c (patch)
tree0acef72aedd5667a1f343be75d42f08a87df3c2c
parent170fa46359162b7ad63b9135050e0e5675d36aca (diff)
downloadpoi-0fdbc396e456b99200a968e076be86ae95b2188c.tar.gz
poi-0fdbc396e456b99200a968e076be86ae95b2188c.zip
Bug 57838: Also remove comments when removing a row
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1746062 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java14
-rw-r--r--src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFComment.java33
-rw-r--r--test-data/spreadsheet/57838.xlsxbin0 -> 9675 bytes
3 files changed, 37 insertions, 10 deletions
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
index 98d7f6c1cf..a328f2ad93 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
@@ -409,7 +409,6 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
/**
* 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 POIXMLDocumentPart implements Sheet {
* 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 POIXMLDocumentPart implements Sheet {
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);
+ }
+ }
+ }
}
/**
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFComment.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFComment.java
index 717fc4e6bc..dac2095ae6 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFComment.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFComment.java
@@ -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 static org.junit.Assert.*;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
+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 extends BaseTestCellComment {
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();
+ }
}
diff --git a/test-data/spreadsheet/57838.xlsx b/test-data/spreadsheet/57838.xlsx
new file mode 100644
index 0000000000..59366d0440
--- /dev/null
+++ b/test-data/spreadsheet/57838.xlsx
Binary files differ