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
This commit is contained in:
Javen O'Neal 2016-09-22 07:50:33 +00:00
parent 551d46f3c1
commit 596bba0962
2 changed files with 7 additions and 6 deletions

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);
}
}

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);