Free Support Forum - aspose.com

Add row to table

Hello I am testing Aspose Words for .Net and want to use instead of Office automation in an existing application. But I am having some trouble getting it to work. I have existing code that looks for bookmarks and then finds a table at the bookmark and adds rows with text in the table.

I can find the bookmark and then the correct table. I have test code that copies the last row and appends it and then saves the document. But when I open the document the table is not altered. Here is part of the code that does not work:

foreach (var node in extractedNodesInclusive)

{

if (node is Table)
{
for (int i = 0; i < 10; i++)
{
Node newRow = ((Table)node).LastRow.Clone(true);
((Table)node).AppendChild(newRow);
}


}
}


Hi Anders,


Thank you for your interest in Aspose.Words. Sure, you can clone the last row and append it at the end of Table by usingthe following code snippet:

Table tab = doc.FirstSection.Body.Tables[0];

// Clone last Row 10 times

for (int i = 0; i < 10; i++)

{

Node newRow = tab.LastRow.Clone(true);

tab.AppendChild(newRow);

}


I hope, this helps.

Best regards,