分割テーブル

Contents
[ ]

Aspose.Wordsドキュメントオブジェクトモデルで表されるテーブルは、独立した行とセルで構成されているため、テーブルを簡単に分割できます。

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

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

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

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

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C.git.
auto doc = MakeObject<Document>(MyDir + u"Tables.docx");
auto firstTable = System::ExplicitCast<Table>(doc->GetChild(NodeType::Table, 0, true));
// We will split the table at the third row (inclusive).
SharedPtr<Row> row = firstTable->get_Rows()->idx_get(2);
// Create a new container for the split table.
auto table = System::ExplicitCast<Table>(firstTable->Clone(false));
// Insert the container after the original.
firstTable->get_ParentNode()->InsertAfter(table, firstTable);
// Add a buffer paragraph to ensure the tables stay apart.
firstTable->get_ParentNode()->InsertAfter(MakeObject<Paragraph>(doc), firstTable);
SharedPtr<Row> currentRow;
do
{
currentRow = firstTable->get_LastRow();
table->PrependChild(currentRow);
} while (currentRow != row);
doc->Save(ArtifactsDir + u"WorkingWithTables.SplitTable.docx");
view raw split-table.h hosted with ❤ by GitHub