Free Support Forum - aspose.com

Change the mergeFields value to an html text

I’m using Aspose Word for Java v11 with ms word 2010 and I want to change the mergeFields value to an html text, my Source code is like this:

builder.moveToMergeField("test");
builder.insertHtml(" Hello word");

The problem is I want the mergefields still on the same format (font, size,color,style...), so can you help me please ?

This message was posted using Email2Forum by simon.bell.

Hi Yasser,


Thanks for your inquiry. Please check my reply at following forum link.
https://forum.aspose.com/t/49139

Hi,


Thanks for your inquiry. I think, you can use the following code snippet to be able to merge the formatting that is specified inside Html string with the formatting of MergeField:

Document doc = new Document(@“C:\test\in.docx”);

DocumentBuilder builder = new DocumentBuilder(doc);<o:p></o:p>

builder.MoveToMergeField(“mf”, false, false);<o:p></o:p>

InsertHtmlWithBuilderFormatting(builder, " Hello word");<o:p></o:p>

// Just to remove the mergefield<o:p></o:p>

builder.MoveToMergeField(“mf”);<o:p></o:p>

doc.Save(@“C:\test\out.docx”);


Please find attached the InsertHtmlWithBuilderFormatting routine with this post.

I hope, this helps.

Best Regards,

Hi Awais,


Thanks for your replay, but i’m programming with Java, can you attach the java code of “insertHtmlWithBuilderFormatting”.


Best regards,

Hi Yasser,


Thanks for your request. I have attached the Java equivalent of InsertHtmlWithBuilderFormatting here with this post. Please try using the following code snippet:
Document doc = new Document(“C:\Temp\mf.docx”);
DocumentBuilder builder = new DocumentBuilder(doc);

builder.moveToMergeField(“mf”, false, false);

DocumentBuilderHelper helper = new DocumentBuilderHelper(builder);
helper.insertHtmlWithBuilderFormatting(formatted html string);

// Just to remove the mergefield
builder.moveToMergeField(“mf”);

doc.save(“C:\Temp\outJava.docx”);

I hope, this helps.

Best Regards,

Great work!


Thank you Awais. awais.hafeez is not online. Last active: 11-27-2012, 4:41 AM

Hi Yasser,


Thanks for your feedback. Please let us know any time you have any further queries. We’re always glad to help you.

Best regards,