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

Free Support Forum - aspose.com

Find Table ID Using a Bookmark

I am trying to find a way to find the ID of a table that contains a bookmark.

I can get to the table node using this code

Dim bk As Bookmark
Dim tbl As Node
bk = doc.Range.Bookmarks(“bookmark”)
tbl = bk.BookmarkStart.GetAncestor(NodeType.Table)

But I can not see a way to get the table ID from the Node.

The Goal is to enter text into the cells in the table that contains this bookmark. My plan was to get the ID and use the MoveToCell function of the documentbuilder.

Is there a way to get the table ID from the node, or is there a better way to do this?

Thanks

Hi Brad,


Thanks for your inquiry. I am afraid, you can not get ID of a Table. You need to get a reference to the Table and then iterate through Rows and Cells collections to be able to set their content. For example, please see the following code and you can use a similar approach to set Cell content:

Document doc = new
Document(MyDir + “Table.Document.doc”);

// Here we get all tables from the Document node. You can do this for any other composite node

// which can contain block level nodes. For example you can retrieve tables from header or from a cell

// containing another table (nested tables).

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

// Iterate through all tables in the document

foreach (Table table in tables)

{

// Get the index of the table node as contained in the parent node of the table

int tableIndex = table.ParentNode.ChildNodes.IndexOf(table);

Console.WriteLine("Start of Table {0}", tableIndex);

// Iterate through all rows in the table

foreach (Row row in table.Rows)

{

int rowIndex = table.Rows.IndexOf(row);

Console.WriteLine("\tStart of Row {0}", rowIndex);

// Iterate through all cells in the row

foreach (Cell cell in row.Cells)

{

int cellIndex = row.Cells.IndexOf(cell);

// Get the plain text content of this cell.

string cellText = cell.ToString(SaveFormat.Text).Trim();

// Print the content of the cell.

Console.WriteLine("\t\tContents of Cell:{0} = \"{1}\"", cellIndex, cellText);

}

//Console.WriteLine();

Console.WriteLine("\tEnd of Row {0}", rowIndex);

}

Console.WriteLine("End of Table {0}", tableIndex);

Console.WriteLine();

}


I hope, this helps.

Best regards,