Reading Tables only at first level

Hello Support,

I want to read tables from documents which are at first level only and make its header row repetable if content of tables extends to multiple pages.

How to do this?

Thanks in advance.

Regards
Mandar

Hi Mandar,

Thanks for your inquiry. Please use RowFormat.HeadingFormat property to repeat the row as table heading on every page when the table spans more than one page. Please set the value of this property to true.

Regarding reading table, could you please share some more detail about reading first level tables? Please also share your input document here for our reference. We will then provide you more information on this along with code example?

Hello Support
Thanks for reply. Please see attached document.
I only want to get tables 1,2 and 3 not 4.

I hope now the it is clear.

Thanks in advance.

Regards
Mandar

Hello
Will it be fine use srcDoc.FirstSection.Body.GetChildNodes(NodeType.Table, false);
I am getting proper count for sample document.

Regards
Mandar

Hi Mandar,

Thanks for your inquiry. You can get the correct table’s count using srcDoc.FirstSection.Body.GetChildNodes(NodeType.Table, false). However, the third table contains the nested table.

In your case, we suggest you following solution. Hope this helps you.

Document doc = new Document(MyDir + "tables.docx");
// Clone the document
Document cloneDoc = (Document)doc.Clone(true);
NodeCollection tables = cloneDoc.GetChildNodes(NodeType.Table, true);
foreach (Table table in tables.Cast<Table>().Where(tbl => tbl.GetChildNodes(NodeType.Table, true).Count > 0))
    table.GetChildNodes(NodeType.Table, true).Clear();
foreach (Table table in tables)
    Console.WriteLine(table.ToString(SaveFormat.Text));

Hello
I looped for each section first and then used body.getchildnodes logic. As I do not want to remove tables at subsequent level but only want to make first row as repeat header for first level tables.
You can close ticket.

Regards
Mandar

Hi Mandar,

Thanks for your feedback. The code in my previous post deletes the nested table from the cloned document. It is nice to hear from you that your problem has been solved. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.