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);
builder.MoveToMergeField("mf", false, false);
InsertHtmlWithBuilderFormatting(builder, " Hello word");
// Just to remove the mergefield
builder.MoveToMergeField("mf");
doc.Save(@"C:\test\out.docx");
Please find attached the InsertHtmlWithBuilderFormatting routine with this post.
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");
public void InsertHtml(string html, bool useBuilderFormatting)
But our program still doesn’t work as expected. We use following code to insert HTML into MergeField
final Document doc = new Document(template);
final DocumentBuilder builder = new DocumentBuilder(doc);
...
builder.moveToMergeField(fieldKey, false, false);
builder.insertHtml(HTMLContent,true);
builder.moveToMergeField(fieldKey);
...
doc.save(targetDocx);
@zwei Thank you for additional information. I am afraid, there is no way to produce the expected output by inserting HTML into the document. first of all structure of your HTML is the following: