分割テーブル

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-Python-via-.NET.git.
doc = aw.Document(MY_DIR + "Tables.docx")
first_table = doc.get_child(aw.NodeType.TABLE, 0, True).as_table()
# We will split the table at the third row (inclusive).
row = first_table.rows[2]
# Create a new container for the split table.
table = first_table.clone(False).as_table()
# Insert the container after the original.
first_table.parent_node.insert_after(table, first_table)
# Add a buffer paragraph to ensure the tables stay apart.
first_table.parent_node.insert_after(aw.Paragraph(doc), first_table)
while True:
current_row = first_table.last_row
table.prepend_child(current_row)
if current_row == row:
break
doc.save(ARTIFACTS_DIR + "WorkingWithTables.split_table.docx")
view raw split-table.py hosted with ❤ by GitHub