How to Delete the rows in a table using aspose.word in a word document? Help Needed Urgently

How to Delete the rows in a table using aspose.word in a word document? I had a requirement where i do have some 20 rows in table. based on the DB values i want to delete the rows. Can Any body please explain or clarify. Its urgent
I am using Asp.net(3.0) with c#

If anyone worked on below requirement please kindly suggest or help
Its Urgent
Thanks in Advance

Hi

Thanks for your request. Every node in Aspose.Words DOM has a method Remove. When you call this method the corresponding node is removed from the document. So to remove a row from the table you should just call Remove method on the corresponding row:
https://reference.aspose.com/words/net/aspose.words/node/remove/
Please let us know if you need more assistance, we will be glad to help you.
Best regards,

THe code you have given is removing all the tables in the document. But my requirement is in such a way that for exmaple in table i have 25 rows and then if i say 8 then remaining below 17 rows should get deleted automatically.
Could you please help with this

Hi
Thanks for your request. The code provide in the article demonstrate the technique, how you can remove nodes from the document. The same technique you can use to remove rows from the table. For instance, see the following code:

// Open template.
Document doc = new Document(@"Test001\in.doc");
// Get table where you need to remove rows.
Table table = (Table) doc.GetChild(NodeType.Table, 0, true);
// Remove the first row of the table.
if (table != null)
    table.Rows[0].Remove();
// Save the result.
doc.Save(@"Test001\out.doc");

Best regards,

hi

how can I delete a row based on a cell value?+
for example if a cell value equals to zero then remove the row.

@ashkanyo Once you detected the cell, you can simply remove it’s parent row. OR you can use code like this:

Document doc = new Document(@"C:\Temp\in.docx");

// Get the table
Table table = doc.FirstSection.Body.Tables[0];

foreach (Row r in table.Rows)
{
    // Check if the first cell value is zero
    if (r.FirstCell.ToString(SaveFormat.Text).Trim() == "0")
        r.Remove();
}

doc.Save(@"C:\Temp\out.docx");