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

Free Support Forum - aspose.com

How to replace a word with html?

I have a document with a word token ie “” the " is not part of the token the < denotes the start and > the end of the token. How do I find and replace all instances of the token with html? I can do standard word replace but not html. It inserts the html as text. The token is simple text in the document not bookmark etc.


Thanks for your inquiry. You can use DocumentBuilder.InsertHtml() For replacing matched text with HTML. Please check following sample code snippet using IReplacingCallback for the purpose.

// Split the last run that contains the match if there is any text left.

if ((currentNode != null) && (remainingLength > 0))


SplitRun((Run)currentNode, remainingLength);

// Create instance of DocumentBuilder and insert document
DocumentBuilder builder = new DocumentBuilder(e.MatchNode.Document as Document);

builder.MoveTo((Run)runs[runs.Count - 1]);


// Now remove all runs in the sequence.

foreach (Run run in runs)

// Signal to the replace engine to do nothing because we have already done all what we wanted.
return ReplaceAction.Skip; 


Thank you I will give that a go.