Browse Source

bug 59687: correctly delete comments from rows when removing a row and the workbook contains empty rows above the deleted row; patch from Greg Woolsey

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1761861 13f79535-47bb-0310-9956-ffa450edef68
tags/REL_3_16_BETA1
Javen O'Neal 7 years ago
parent
commit
3300d54179

+ 6
- 4
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java View File

@@ -1928,15 +1928,17 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
}

// Performance optimization: explicit boxing is slightly faster than auto-unboxing, though may use more memory
final Integer rownumI = new Integer(row.getRowNum()); // NOSONAR
int idx = _rows.headMap(rownumI).size();
_rows.remove(rownumI);
final int rowNum = row.getRowNum();
final Integer rowNumI = new Integer(rowNum); // NOSONAR
// this is not the physical row number!
final int idx = _rows.headMap(rowNumI).size();
_rows.remove(rowNumI);
worksheet.getSheetData().removeRow(idx);

// also remove any comment located in that row
if(sheetComments != null) {
for (CellAddress ref : getCellComments().keySet()) {
if (ref.getRow() == idx) {
if (ref.getRow() == rowNum) {
sheetComments.removeComment(ref);
}
}

+ 1
- 2
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java View File

@@ -2022,8 +2022,7 @@ public final class TestXSSFSheet extends BaseTestXSheet {
}
// bug 59687: XSSFSheet.RemoveRow doesn't handle row gaps properly when removing row comments
// This test is currently failing (thus expected AssertionError). When this bug is fixed, no error should be thrown.
@Test(expected=AssertionError.class)
@Test
public void testRemoveRowWithCommentAndGapAbove() throws IOException {
final Workbook wb = _testDataProvider.openSampleWorkbook("59687.xlsx");
final Sheet sheet = wb.getSheetAt(0);

Loading…
Cancel
Save