Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
A table, represented in the Aspose.Words Document Object Model, is made up of independent rows and cells, making it easy to split a table.
To manipulate a table to split it into two tables, we just need to move some of the rows from the original table to the new one. To do this, we need to pick the row by which we want to split the table.
We can create two tables from the original table by following these simple steps:
The following code example shows how to split a table into two tables on a specific row:
// 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"); |
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.