I have a document and there is a table with headers in it and rows need to be added dynamically from the List
generating PDF through ASPOSE.Words
I need to add the rows dynamically to the existing table in the document
Please find the code as below:
I am getting the table and cloning the row.
But how do i add the values to the cells in the row.
Thanks for your inquiry. Please check following code snippet. Hopefully it would serve the purpose.
Document doc = new Document(MyDir + "CAPSHEET.docx");
// Retrieve the first table in the document.
Table table = (Table)doc.getChild(NodeType.TABLE, 0, true);
// Clone the last row in the table.
Row clonedRow = (Row)table.getLastRow().deepClone(true);
// Remove all content from the cloned row's cells. This makes the row ready for
// new content to be inserted into.
for (Cell cell: clonedRow.getCells())
{
cell.getFirstParagraph().getRuns().clear();
cell.getFirstParagraph().appendChild(new Run(doc, "hello text"));
}
// Add the row to the end of the table.
table.appendChild(clonedRow);
doc.save(MyDir + "Table.AddCloneRowToTable Out.doc");
Please feel free to contact us for any further assistance.
Thanks for your inquiry. You can use the following code to make a clone of the last row of a table and append it to the table.
// Retrieve the first table in the document.
Table table = (Table)doc.GetChild(NodeType.Table, 0, true);
// Clone the last row in the table.
Row clonedRow = (Row)table.LastRow.Clone(true);
// Remove all content from the cloned row’s cells. This makes the row ready for
// new content to be inserted into.
foreach (Cell cell in clonedRow.Cells)
cell.RemoveAllChildren();
// Add the row to the end of the table.
table.AppendChild(clonedRow);