แยกโต๊ะ

Contents
[ ]

ตารางที่แสดงใน Aspose.Words Document Object Model ประกอบด้วยแถวและเซลล์ที่เป็นอิสระ ทำให้แยกตารางได้ง่าย

หากต้องการจัดการตารางให้แยกออกเป็นสองตาราง เราเพียงแค่ต้องย้ายแถวบางแถวจากตารางเดิมไปยังตารางใหม่ เมื่อต้องการทำเช่นนี้ เราจำเป็นต้องเลือกแถวที่เราต้องการแยกตาราง

เราสามารถสร้างตารางสองตารางจากตารางต้นฉบับได้โดยทำตามขั้นตอนง่ายๆ เหล่านี้:

  1. สร้างโคลนของตารางโดยไม่ต้องโคลนเด็ก ๆ เพื่อเก็บแถวที่ถูกย้ายและแทรกไว้หลังตารางต้นฉบับ
  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