Free Support Forum - aspose.com

Delete the tables

Hi!

I need to delete all tables with one row in document.

How I do this ?

private void DeleteTables()

{

try {

Aspose.Words.Sections tabSections = AsposeDocument.Sections;

foreach (Aspose.Words.Section section in tabSections )

{

Aspose.Words.Tables tables = section.Body.Tables;

foreach( Aspose.Words.Table table in tables )

{

if (table.Rows.Count == 1)

{

???????????????????????????

}

}

}

}

Thank's

Isabel

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. I think that you can try using the following code to achieve this.

Document doc = new Document(@"Test089\in.doc");

//Get collection of tables

NodeCollection tables = doc.GetChildNodes(NodeType.Table, true);

//Loop through all tables

for (int tableIndex = 0; tableIndex < tables.Count; )

{

if ((tables[tableIndex] as Table).Rows.Count == 1)

tables[tableIndex].Remove();//Remove table

else

tableIndex++;//Increase index

}

//Save document

doc.Save(@"Test089\out.doc");

Hope this helps.

Best regards.

Hi!

This code is very usefull.

Thank's.

Isabel