We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Getting TableIndex of Nested Table

Hi there!

Suppose you have a document with 5 tables.
#0 and #1 are “normal” tables, i.e. there are no nested tables inside those two.
#2 has table #3 as a nested table and #4 is a “normal” table again.

When using documentBuilder.moveToCell the first parameter is the TableIndex. How to I get the Index of the correct table?

At the moment I find the correct table by utilising a bookmark with the “Name” of the table in the first row/first column of the table.

With this I use the command tableIndex = oCurrentSection.Body.Tables.IndexOf(oTable) to get the index of the table.
With #0,#1 and #2 this is OK but from then on, this approach does not work because table #3 is obviously not a member of the collection of Tables of the Body and therefore can’t be found and table #4 reports an TabIndex of 3 as if #4 where not there at all. How to I find out the correct TableIndex?

I’m using VB6 with COM-Interop

Best Regards,

Hi Michael,

Thanks for your inquiry. I am checking with this scenario and will get back to you soon.


i finally figured it out, this is the code I use to get the index of a (nested) table:

Function getTableIndex( _
oTable As Aspose_Words.Table, _
oDocument As Aspose_Words.Document) _
As Long
Dim oCurrentSect As Aspose_Words.Section
Dim i As Long
Dim oNode As Aspose_Words.Node
Set oCurrentSect = oTable.GetAncestor_2(NodeType_Section)
For Each oNode In oCurrentSect.GetChildNodes(NodeType_Table, True)
If oNode.Equals(oTable) Then
getTableIndex = i - 1
Exit Function
End If
i = i + 1
End Function

Best regards,
Hi Michael,

Please accept my apologies for late response.

Please use the NodeCollection.IndexOf Method to get the index of table. This method returns the zero-based index of the specified node. The zero-based index of the node within the collection, if found; otherwise, -1.

It is nice to hear from you that you have solved your problem. You can use the following code snippet to get the index of all tables including nested tables.

Document doc = new Document(MyDir + "in.docx");

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

foreach (Table table in allTables)


int tableIndex = allTables.IndexOf(table);