ตารางแยก

Contents
[ ]

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

ในการจัดการกับตารางที่จะแยกออกเป็นสองตารางเราก็ต้องย้ายบางส่วนของแถวจากต การทำเช่นนี้เราต้องเลือกแถวโดยที่เราต้องการที่จะแยกตาราง.

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

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