Dividi tabella

Contents
[ ]

Una tabella, rappresentata nel modello a oggetti del documento Aspose.Words, è composta da righe e celle indipendenti, semplificando la suddivisione di una tabella.

Per manipolare una tabella per dividerla in due tabelle, dobbiamo solo spostare alcune delle righe dalla tabella originale a quella nuova. Per fare ciò, dobbiamo scegliere la riga con cui vogliamo dividere la tabella.

Possiamo creare due tabelle dalla tabella originale seguendo questi semplici passaggi:

  1. Creare un clone della tabella senza clonare i figli per mantenere le righe spostate e inserirle dopo la tabella originale
  2. A partire dalla riga specificata, spostare tutte le righe successive in questa seconda tabella

L’esempio di codice seguente mostra come dividere una tabella in due tabelle su una riga specifica:

// 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