拆分表
Contents
[
Hide
]
由 Aspose.Words Document Object Model 所表示的資料表是由獨立的列與細胞組成的,使其易於將資料表分開。
若要將一張表格分成兩張表格,我們只需要將原表中的部份資料列移動到新表中。 要完成這件事,我們必須選擇要分割表格的地方。
我們可以根據這些簡單的步驟,從原始表格中創造兩個表格:
- 創建一個不複製子節點的表格副本,以保留移動的列並將其插入到原始表格之後 2。 從指定的行開始,將所有接下來的行移動到這個第二個表格中
以下程式碼範例示範如何在一特定行上將一張表分割成兩張:
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"); | |
Table firstTable = (Table) doc.GetChild(NodeType.Table, 0, true); | |
// We will split the table at the third row (inclusive). | |
Row row = firstTable.Rows[2]; | |
// Create a new container for the split table. | |
Table table = (Table) firstTable.Clone(false); | |
// Insert the container after the original. | |
firstTable.ParentNode.InsertAfter(table, firstTable); | |
// Add a buffer paragraph to ensure the tables stay apart. | |
firstTable.ParentNode.InsertAfter(new Paragraph(doc), firstTable); | |
Row currentRow; | |
do | |
{ | |
currentRow = firstTable.LastRow; | |
table.PrependChild(currentRow); | |
} while (currentRow != row); | |
doc.Save(ArtifactsDir + "WorkingWithTables.SplitTable.docx"); |