]> source.dussan.org Git - poi.git/commitdiff
CTRow removes tc when row removes cell
authorSayi <sayi@apache.org>
Tue, 1 Sep 2020 11:56:13 +0000 (11:56 +0000)
committerSayi <sayi@apache.org>
Tue, 1 Sep 2020 11:56:13 +0000 (11:56 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1881354 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableRow.java
src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableRow.java

index c3a6755c3b4c3974489817fec8be2b16241bcd14..e79f7d2c16c8ed4afb9be00103d220d429ccc267 100644 (file)
@@ -74,6 +74,7 @@ public class XWPFTableRow {
     public void removeCell(int pos) {
         if (pos >= 0 && pos < ctRow.sizeOfTcArray()) {
             tableCells.remove(pos);
+            ctRow.removeTc(pos);
         }
     }
 
index 383e5c3c94adb77cad644372c6955f955e0cff42..620b59e7ce1cc0a8a8adcdfd92d48a2ed59b65b0 100644 (file)
@@ -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