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

Free Support Forum - aspose.com

Removing Parts of a Document

We would like to open a Word Document and remove everything between a start and finish tag which we define, including tables, images etc… I’ve attached a sample document where we would like to remove all of the text between <hs=sectionOne> and </hs=sectionOne>. How can I accomplish this using Aspose Words? Thanks in advance.



Here is the code that I’m using to replace everything, but the table is not being removed.

Pattern pattern = Pattern.compile("\<hs=sectionOne\>.*\<\/hs=sectionOne\>", Pattern.DOTALL);
com.aspose.words.Document document = new com.aspose.words.Document("c:\in.docx);
int results = document.getRange().replace(pattern, “”, new FindReplaceOptions());
if (results > 0) {
System.out.println(“Removed sectionOne from document”);

This question can be marked as resolved. I was able to insert continuous section breaks into the document and programatically remove the sections that I needed to.

Hi Domenick,

It is great you were able to find what you were looking for. Another way is to enclose part of the document that you want to remove inside a Bookmark (BookmarkStart and BookmarkEnd nodes) and then just assign empty string to Text property of Bookmark as follows:

Bookmark bm = doc.getRange().getBookmarks().get("bm");

Please let us know any time you have any further queries.

Best regards,