From: Sayi Date: Tue, 1 Sep 2020 11:56:13 +0000 (+0000) Subject: CTRow removes tc when row removes cell X-Git-Tag: before_ooxml_3rd_edition~128 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3644bb90941b47a4682c4bbc7b3f3fc608fae028;p=poi.git CTRow removes tc when row removes cell git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1881354 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableRow.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableRow.java index c3a6755c3b..e79f7d2c16 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableRow.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableRow.java @@ -74,6 +74,7 @@ public class XWPFTableRow { public void removeCell(int pos) { if (pos >= 0 && pos < ctRow.sizeOfTcArray()) { tableCells.remove(pos); + ctRow.removeTc(pos); } } diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableRow.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableRow.java index 383e5c3c94..620b59e7ce 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableRow.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableRow.java @@ -17,6 +17,7 @@ package org.apache.poi.xwpf.usermodel; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -141,6 +142,20 @@ public class TestXWPFTableRow { } } + @Test + public void testRemoveCell() throws IOException { + XWPFDocument doc = new XWPFDocument(); + XWPFTableRow tr = doc.createTable(1, 1).createRow(); + + assertEquals(1, tr.getTableCells().size()); + assertEquals(tr.getTableCells().size(), tr.getCtRow().sizeOfTcArray()); + + tr.removeCell(0); + assertEquals(0, tr.getTableCells().size()); + assertEquals(tr.getTableCells().size(), tr.getCtRow().sizeOfTcArray()); + doc.close(); + } + @Test public void testBug62174() throws IOException { try (XWPFDocument doc = XWPFTestDataSamples