Tabela dividida
Uma tabela, representada no Aspose.Words Document Object Model, é composta por linhas e células independentes, facilitando a divisão de uma tabela.
Para manipular uma tabela para dividi-la em duas tabelas, precisamos apenas mover algumas linhas da tabela original para a nova. Para fazer isso, precisamos escolher a linha pela qual queremos dividir a tabela.
Podemos criar duas tabelas a partir da tabela original seguindo estes passos simples:
- Crie um clone da tabela sem clonar os filhos para manter as linhas movidas e insira-as após a tabela original
- Começando na linha especificada, mova todas as linhas subsequentes para esta segunda tabela
O exemplo de código a seguir mostra como dividir uma tabela em duas tabelas em uma linha específica:
// 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"); |