CTRow removes tc when row removes cell

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1881354 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sayi 2020-09-01 11:56:13 +00:00
parent b00ca445b2
commit 3644bb9094
2 changed files with 16 additions and 0 deletions

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

View 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