結合表格
Contents
[
Hide
]
由 Aspose.Words Document Object Model 所表示的表格,是由獨立的列與細胞組成的,讓 bảng dễ與別的 bảng結合。
要操作資料表與另一資料表結合,我們只需將第二資料表的行移動到第一資料表結尾,並移除第二資料表的容器。
以下程式碼示例展示了如何將兩個資料表的欄位合併到一個資料表中:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET.git. | |
Document doc = new Document(MyDir + "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.Rows.Add(secondTable.FirstRow); | |
secondTable.Remove(); | |
doc.Save(ArtifactsDir + "WorkingWithTables.CombineRows.docx"); |