We have a Word Document that will have some merge fields like this;
private class HandleMergeFieldInsertHtml : IFieldMergingCallback
{
///
/// This is called when merge field is actually merged with data in the document.
///
void IFieldMergingCallback.FieldMerging(FieldMergingArgs e)
{
// Insert the text for this merge field as HTML data, using DocumentBuilder.
DocumentBuilder builder = new DocumentBuilder(e.Document);
builder.MoveToMergeField(e.DocumentFieldName);
builder.InsertHtml((string)e.FieldValue);
// The HTML text itself should not be inserted.
// We have already inserted it as an HTML.
e.Text = "";
}
void IFieldMergingCallback.ImageFieldMerging(ImageFieldMergingArgs e)
{
// Do nothing.
}
}
// Create an empty document. It contains one empty paragraph.
Document doc = new Document(MyDir + "in.docx");
// Add a handler for the MergeField event.
doc.MailMerge.FieldMergingCallback = new HandleMergeFieldInsertHtml();
// Execute mail merge.
doc.MailMerge.Execute(new string[] { "html_field" }, new string[] { @" that is bold " });
doc.Save(MyDir + "17.4.0.docx");
Hi
Thanks for the response. I fixed my own problem but your response put me on the right track.
My issue actually turned out to be some code that was replacing CF/LF with [p] instead of [br]. ([] characters used in place of LT & GT)
Thanks Again