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

Free Support Forum - aspose.com

Delete certain table or image merge field

Hi All,
I would like to know can we delete certain section on a generated file? Say we would like to delete a table which contains a total of 0 user. The table normally will display, for example, total | 0. But I would like to delete this table. Or an image merge field which is a chart image (I’m generating chart images using Coldfusion), but because there is no data in the table (all data is 0), the image becomes blank. I’ve read something about using Bookmark in the template file but I don’t really get this one.


Hi Laurentius,

Thank you for your inquiry.
The first thing would be to decide where you need a bookmark. It could be a string of text, a picture or simply a blank space somewhere. Now highlight the text, or select the picture, or put the cursor in the spot where the bookmark should be located. Next you’ll need the Insert menu, Bookmark choice. (Ctrl + Shift + F5 will also open the Bookmark window.)

Use following code snippet to remove table:

// Create document object
Document doc = new Document(“d:/temp/temp.docx”);

// Use the indexer of the Bookmarks collection to obtain the desired bookmark.
Bookmark bookmark = doc.getRange().getBookmarks().get(“MyBookmark”);
//Get the table that this bookmark is contained in.
Table table = (Table) bookmark.getBookmarkStart().getAncestor(NodeType.TABLE);

// Remove the table

I would like to suggest some informational links:




Hope this will help you.

Hi Imran,
Thanks for the reply. I tried your suggestions but I’m still getting this error

Variable bk is undefined.

I’m building the app using Coldfusion. I know I might be asking in the wrong place, but is there any chance you can provide me the sample code using Coldfusion? This is the code I used in my application.

<cfset bk = loader.create(“com.aspose.words.Bookmark”)>
<cfset bk = report.getRange().getBookmarks().get(“bookmark_name”)>
<cfset table = loader.create(“com.aspose.words.Node”)>
<cfset table = bk.getBookmarkStart().getAncestor(NodeType.TABLE)>
<cfset table.Remove()>

Laurentius Raymon

Hi Laurentius,

Thank you for your inquiry. Please share your input Word document for testing purpose to narrow down the problem.

Hi Imran,

All is good now. I’ve managed to solve the problem. Turned out, I don’t need to create the object bookmark and table. Thanks for your guide. It helped a lot.


Hi Laurentius,

Thanks for your details. It is great to hear that you managed to resolve. You are always welcome and please feel free to ask if you have any query in future.

We always welcome constructive response from our customers.