Free Support Forum - aspose.com

How to delete a row in a table- with a bookmark on it

I have a user requirement which can be achieved by MS Office Word API:


- There’s a Word (.doc) file, with Multiple tables in it. Multiple rows in each table. The no. of table is unknown. The no. of row for each table is unknown.
- In a particular row, there’s a bookmark called “To_Be_Deleted”
- What I need is to locate that row by using the “To_Be_Deleted” bookmark, then delete that table row.

Is it achievable by ASPOSE WORD? It would be nice if kinda sample code can be provided for this requirement. Many thanks

Hi Mark,


Thanks for your inquiry. Please use the Node.GetAncestor method to get the first ancestor of the specified NodeType. In your case, the ancestor of bookmark is Row. Please use the following code snippet to achieve your requirements. Hope this helps you. Please let us know if you have any more queries.

<span lang=“EN-GB” style=“font-size:10.0pt;font-family:“Courier New”;color:#2B91AF;mso-font-kerning:
0pt;mso-no-proof:yes”>Document<span lang=“EN-GB” style=“font-size:10.0pt;
font-family:“Courier New”;mso-font-kerning:0pt;mso-no-proof:yes”> doc = new Document(MyDir

  • “Test04.docx”);<o:p></o:p>

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

Row row = (Row)bm.BookmarkStart.GetAncestor(NodeType.Row);

row.Remove();

doc.Save(MyDir + "out.docx");