Replace HTML with HTML in WORD

Hi!
I’ve encountered an issue when trying to replace the content of a bookmark with html.

1- Created a bookmark in the document.
2- The document is loaded and prepared.
3- With Aspose.Words i move to the desired bookmark and use the InsertHtml() method.
4- Inserts the Html content in the bookmark.
5- When trying to use the same bookmark again to update the document, i can only insert new HTML, not find or replace.
6- When searching through the nodes, childs, parents, etc, i’ve never found the previously inserted HTML. The only place with the text is in the document text, which i can’t use to replace with HTML.

So, is it possible to replace html within the bookmarks?

@amora92,

If you want to search the content along with HTML markup, please try DocumentBuilder.Write method instead of DocumentBuilder.InsertHtml. Please see these sample input/output Word documents (Docs.zip (17.6 KB)) and try running the following code:

Document doc = new Document("E:\\Temp\\in.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToBookmark("bm");
builder.InsertHtml("<b>Bold Text</b>");
//builder.Write("<b>Bold Text</b>");
doc.Save("E:\\Temp\\19.7.docx");

//// it will find 1 Occurrence 
//Console.WriteLine(doc.Range.Replace("Bold Text", ""));

//// it will find 0 Occurrence 
//Console.WriteLine(doc.Range.Replace("<b>Bold Text</b>", ""));

@awais.hafeez But in a case where a table or any other html element is inserted the replace, to my understanding, will only apply to the text. Am i correct? If so, how do i replace any element inserted with the InsertHtml method?

@amora92,

We are investigating this issue and will get back to you soon.

@tahir.manzoor ok, thank you! waiting for an answer :slight_smile:

@amora92,

To ensure a timely and accurate response, please ZIP and attach the following resources here for testing:

  • Your simplified input document (.html string/file)
  • Aspose.Words generated output document showing the undesired behavior
  • Your expected document showing the correct output. You can create expected document by using MS Word.
  • Please also list the steps that we can perform on our end to reproduce the problem
  • Please also create a simplified standalone application (source code without compilation errors) that helps us to reproduce your current problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we will start further investigation into your scenario and provide you more information. Thanks for your cooperation.