Author: onealj Date: Thu Sep 22 07:50:33 2016 New Revision: 1761861 URL: http://svn.apache.org/viewvc?rev=1761861&view=rev Log: 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
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.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=1761861&r1=1761860&r2=1761861&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 Thu Sep 22 07:50:33 2016 @@ -1928,15 +1928,17 @@ public class XSSFSheet extends POIXMLDoc } // 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); } } Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java?rev=1761861&r1=1761860&r2=1761861&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java Thu Sep 22 07:50:33 2016 @@ -2022,8 +2022,7 @@ public final class TestXSSFSheet extends } // 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); --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@poi.apache.org For additional commands, e-mail: commits-h...@poi.apache.org