Tabella divisa
Una tabella, rappresentata nel Aspose.Words Document Object Model, è composta da righe e celle indipendenti, facilitando la divisione di una tabella.
Per manipolare una tabella per dividerla in due tabelle, dobbiamo solo spostare alcune righe dalla tabella originale a quella nuova. Per fare ciò, dobbiamo scegliere la riga in base alla quale vogliamo dividere la tabella.
Possiamo creare due tabelle dalla tabella originale seguendo questi semplici passaggi:
- Crea un clone della tabella senza clonare i figli per mantenere le righe spostate e inserirle dopo la tabella originale
- Iniziando 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-.NET.git. | |
Document doc = new Document(MyDir + "Tables.docx"); | |
Table firstTable = (Table) doc.GetChild(NodeType.Table, 0, true); | |
// We will split the table at the third row (inclusive). | |
Row row = firstTable.Rows[2]; | |
// Create a new container for the split table. | |
Table table = (Table) firstTable.Clone(false); | |
// Insert the container after the original. | |
firstTable.ParentNode.InsertAfter(table, firstTable); | |
// Add a buffer paragraph to ensure the tables stay apart. | |
firstTable.ParentNode.InsertAfter(new Paragraph(doc), firstTable); | |
Row currentRow; | |
do | |
{ | |
currentRow = firstTable.LastRow; | |
table.PrependChild(currentRow); | |
} while (currentRow != row); | |
doc.Save(ArtifactsDir + "WorkingWithTables.SplitTable.docx"); |