So I am using Aspose.Word.DocumentBuilder to go to a particular part of a document. I want to do the following:
[VB]
If (docBuilder.CurrentParagraph.ParentNode.NodeType = Aspose.Word.NodeType.Cell) Then
docBuilder.MoveToCell( a, b, c, 0)
End If
where a, b, and c are, respectively, the table index, row index, and column index of the current location of docBuilder. The problem is, I do not know, and cannot find any documentation on, how to get these indices. Does any one know or can anyone point me in the right direction?
Hi
Thanks for your request. Try to use the following code to get these indexes.
Dim tabIndex As Integer
Dim rowIndex As Integer
Dim cellIndex As Integer
Dim table As Table = Nothing
For Each table In doc.FirstSection.Body.Tables
'get index of current table
tabIndex = doc.FirstSection.Body.Tables.IndexOf(table)
Dim row As Row = Nothing
For Each row In doc.FirstSection.Body.Tables(tabIndex).Rows
'get indext of current row
rowIndex = table.Rows.IndexOf(row)
Dim cell As Cell = Nothing
For Each cell In doc.FirstSection.Body.Tables(tabIndex).Rows(rowIndex).Cells
'get index of current cell
cellIndex = row.Cells.IndexOf(cell)
builder.MoveToCell(tabIndex, rowIndex, cellIndex, 0)
builder.Write(String.Format("Table #{0}; Row #{1}; Cell #{2}", tabIndex.ToString(), rowIndex.ToString(), cellIndex.ToString()))
Next
Next
Next
Dim doc As New Document(MyDir & "Bookmark.doc")
Dim bookmark As Bookmark = doc.Range.Bookmarks("bookmark")
Dim table As Table = CType(bookmark.BookmarkStart.ParentNode.GetAncestor(NodeType.Table),Table)
If (Not (table) Is Nothing) Then
Console.WriteLine(doc.GetChildNodes(NodeType.Table, true).IndexOf(table))
End If