How to find a table present in word document using C#

Hi Team,

We are doing a small POC using Aspose.Word.

We have a situation where we have two tables present in the word document along with other data.

We want to access one table from the document and we will traverse to the cell of that table and do the changes.

However we are facing issue in finding that table in the document. We don’t want to use the indexing like table0 or table1 to find the table, as we may add more table later in the document like below

// Get the Second table in the document.
Table table = (Table)doc.GetChild(NodeType.Table, 1, true);


Is there any other way means defining any style or assigning any name to teh table, so that we can search the particular table in the document by that and can do the changes there?

Could you please suggest on this?

Thanks,
Rajesh

Hi Rajesh,

Thanks for your inquiry. In your case, I suggest you please insert the bookmark inside first cell of each table e.g table 1, table 2 etc and use following code example to get the specific table. Hope this helps you.

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

Bookmark bm = doc.Range.Bookmarks["table1"];

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