mirror of
https://github.com/apache/poi.git
synced 2025-02-08 02:58:18 +00:00
add removeTable method in cell
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1880739 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a8d90aba91
commit
8329582036
@ -421,6 +421,18 @@ public class XWPFTableCell implements IBody, ICell {
|
||||
tables.add(i, table);
|
||||
}
|
||||
|
||||
/**
|
||||
* removes a table of this table cell
|
||||
*
|
||||
* @param pos The position in the list of tables, 0-based
|
||||
*/
|
||||
public void removeTable(int pos) {
|
||||
XWPFTable removedTable = tables.get(pos);
|
||||
tables.remove(pos);
|
||||
ctTc.removeTbl(pos);
|
||||
bodyElements.remove(removedTable);
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
StringBuilder text = new StringBuilder();
|
||||
for (XWPFParagraph p : paragraphs) {
|
||||
|
@ -28,6 +28,7 @@ import org.junit.Test;
|
||||
|
||||
import org.apache.poi.xwpf.XWPFTestDataSamples;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFTableCell.XWPFVertAlign;
|
||||
import org.apache.xmlbeans.XmlCursor;
|
||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHMerge;
|
||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTShd;
|
||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl;
|
||||
@ -214,6 +215,31 @@ public class TestXWPFTableCell {
|
||||
doc.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveTable() throws Exception {
|
||||
XWPFDocument doc = new XWPFDocument();
|
||||
XWPFTable table = doc.createTable();
|
||||
XWPFTableRow tr = table.createRow();
|
||||
XWPFTableCell cell = tr.addNewTableCell();
|
||||
|
||||
// cell have at least one paragraph by default
|
||||
XWPFParagraph p0 = cell.getParagraphArray(0);
|
||||
XmlCursor newCursor = p0.getCTP().newCursor();
|
||||
cell.insertNewTbl(newCursor);
|
||||
newCursor.dispose();
|
||||
|
||||
assertEquals(1, cell.getTables().size());
|
||||
assertEquals(2, cell.getBodyElements().size());
|
||||
|
||||
// remove table
|
||||
cell.removeTable(0);
|
||||
assertEquals(0, cell.getTables().size());
|
||||
assertEquals(1, cell.getBodyElements().size());
|
||||
assertEquals(p0, cell.getBodyElements().get(0));
|
||||
|
||||
doc.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug63624() throws Exception {
|
||||
XWPFDocument doc = new XWPFDocument();
|
||||
|
Loading…
x
Reference in New Issue
Block a user