分割テーブル

Contents
[ ]

Aspose.Words Document Object Model で表されるテーブルは独立した行とセルで構成されているため、テーブルを簡単に分割できます。

テーブルを操作して 2 つのテーブルに分割するには、元のテーブルから新しいテーブルに行の一部を移動するだけです。これを行うには、テーブルを分割する行を選択する必要があります。

次の簡単な手順に従って、元のテーブルから 2 つのテーブルを作成できます。

  1. 子のクローンを作成せずにテーブルのクローンを作成して、移動した行を保持し、元のテーブルの後に挿入します。
  2. 指定された行から開始して、後続のすべての行をこの 2 番目のテーブルに移動します。

次のコード例は、テーブルを特定の行で 2 つのテーブルに分割する方法を示しています。

// 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");
view raw split-table.cs hosted with ❤ by GitHub