连接表

Contents
[ ]

在Aspose.Words文档对象模型中表示的表由独立的行和单元格组成,因此可以轻松连接表。

要操作一个表与另一个表连接,我们只需要将第二个表中的行移动到第一个表的末尾,并删除第二个表的容器。

下面的代码示例演示如何将两个表中的行合并为一个表:

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java.git.
Document doc = new Document(getMyDir() + "Tables.docx");
// The rows from the second table will be appended to the end of the first table.
Table firstTable = (Table) doc.getChild(NodeType.TABLE, 0, true);
Table secondTable = (Table) doc.getChild(NodeType.TABLE, 1, true);
// Append all rows from the current table to the next tables
// with different cell count and widths can be joined into one table.
while (secondTable.hasChildNodes())
firstTable.getRows().add(secondTable.getFirstRow());
secondTable.remove();
doc.save(getArtifactsDir() + "WorkingWithTables.CombineRows.docx");