Tabla dividida
Una tabla, representada en el modelo de objetos de documento Aspose.Words, se compone de filas y celdas independientes, lo que facilita la división de una tabla.
Para manipular una tabla para dividirla en dos tablas, solo necesitamos mover algunas de las filas de la tabla original a la nueva. Para hacer esto, debemos elegir la fila por la cual queremos dividir la tabla.
Podemos crear dos tablas a partir de la tabla original siguiendo estos sencillos pasos:
- Cree un clon de la tabla sin clonar los hijos para mantener las filas movidas e insertarlas después de la tabla original.
- Comenzando en la fila especificada, mueva todas las filas siguientes a esta segunda tabla.
El siguiente ejemplo de código muestra cómo dividir una tabla en dos tablas en una fila 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"); |