Free Support Forum - aspose.com

Search Tables within Document

Hi,

I am inserting html tables into a word document and would like to search for them when I retrieve the document later.

Currently, I am able to retrieve all the tables using the following syntax.

NodeList allNodes = builder.Document.SelectNodes("//Table");

However, could you please let me know how I can retrieve a specific table(say for e.g. the table had a ID='TableID').

I've tried the following:

NodeList allNodes = builder.Document.SelectNodes("//Table[id='TableID']");

Thanks.

Hi

Thanks for your request. In Ms Word Table nodes cannot have any identifiers. So even if in your HTML the table has ID, in MS Word there will not be any identifier for this table.

However, as a workaround, you can use bookmark as a marker of the table. You can insert bookmark into the first cell of the table and access table by getting a Table object where bookmark is inserted.

// Get bookmark by name

Bookmark bk = doc.Range.Bookmarks["myBookmark"];

// Get Table where bookmark locates.

Table table = (Table)bk.BookmarkStart.GetAncestor(NodeType.Table);

Hope this helps.

Best regards.