Hi Sydney,
From the given details, we found that your requirement is to find a specific
table from a Word document and add a new row to that table. In order to achieve
this,
Suggestion 1:
We suggest you set alternate text, such as a title or description, to the
table. This will allow you to locate the table using the FindItemByProperty
API.
|
//Open an existing Word document
WordDocument doc = new WordDocument(@"Sample.docx");
//Find the table using the table Title
WTable table = doc.FindItemByProperty(EntityType.Table, "Title", "Table2") as WTable;
//Add a row
table.AddRow();
//Save the Word document
doc.Save(@"Output.docx");
|
Alternatively, you can utilize DocIO to set the alternate text for the table.
|
//Specifies the title for the table
table.Title = "Table2";
//Specifies the description of the table
table.Description
= "This
is the second table";
|
Suggestion 2:
Another approach is to find the table by its index within the Word document.
|
//Opens an existing Word document
WordDocument document = new WordDocument(@"Sample.docx");
//Accesses the instance of the first section in the Word
document
WSection section = document.Sections[0];
//Accesses the instance of the second table in the section
WTable table = section.Tables[1] as WTable;
//Add row
table.AddRow();
//Save the document
document.Save(@"Output.docx");
|
Regards,
Sneha.