تقسيم الجدول
يتكون الجدول، الممثل في نموذج كائن المستند Aspose.Words، من صفوف وخلايا مستقلة، مما يسهل تقسيم الجدول.
لمعالجة جدول لتقسيمه إلى جدولين، نحتاج فقط إلى نقل بعض الصفوف من الجدول الأصلي إلى الجدول الجديد. للقيام بذلك، نحن بحاجة إلى اختيار الصف الذي نريد تقسيم الجدول.
يمكننا إنشاء جدولين من الجدول الأصلي باتباع هذه الخطوات البسيطة:
- إنشاء نسخة من الجدول دون استنساخ الأطفال للحفاظ على الصفوف المنقولة وإدراجها بعد الجدول الأصلي
- بدءا من الصف المحدد، انقل جميع الصفوف اللاحقة إلى هذا الجدول الثاني
يوضح مثال التعليمات البرمجية التالية كيفية تقسيم جدول إلى جدولين في صف معين:
// 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"); |