Hi
Thanks for your interest in Aspose products. You should create rtf document and then insert this document into your template. See the following code.
public void TestMailMergeInsertRtf_102888()
{
Document doc = new Document(@"258_102888_raviteja\in.doc");
string[] names = { "Field1" };
string[] values = { "{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\colortbl;\\red0\\green0\\blue0;}{\\fonttbl\n{\\f0\\fswiss\\fcharset1252 Times New Roman;}\n}{\\*\\generator CuteEditor 5.0;}\\viewkind4\\uc1\\pard\\cf1\\f0\\fs24\\qj\\b0\\i0\\ulnone Hi \\cf1\\f0\\fs24\\qj\\b1\\i0\\ulnone this \\cf1\\f0\\fs24\\qj\\b1\\i1\\ulnone is \\cf1\\f0\\fs24\\qj\\b1\\i1\\ul test1}}" };
doc.MailMerge.MergeField += new MergeFieldEventHandler(MailMerge_MergeField_102888);
doc.MailMerge.Execute(names, values);
doc.Save(@"258_102888_raviteja\out.doc");
}
void MailMerge_MergeField_102888(object sender, MergeFieldEventArgs e)
{
if (e.FieldName == "Field1")
{
// Use DocumentBuilder to navigate to merge field with the specified name.
DocumentBuilder builder = new DocumentBuilder(e.Document);
builder.MoveToMergeField(e.DocumentFieldName);
//load rtf string into stream
MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(e.FieldValue.ToString()));
//create document
Document rtfDoc = new Document(stream);
//close stream
stream.Close();
// Content of the specified document are inserted after the paragraph, containing the merge field.
InsertDocument(builder.CurrentParagraph, rtfDoc);
// If the paragraph, containing merge field, does not contain anything else - delete it.
if (builder.CurrentParagraph.ToTxt().Trim() == "")
builder.CurrentParagraph.Remove();
// The field value text is not needed anymore, eraze it.
// Otherwise, it will be inserted at merge field location too.
e.Text = string.Empty;
}
}
The InsertDocument method you can find here.
https://docs.aspose.com/words/net/insert-and-append-documents/
I hope that this will help you.
Please let me know if you would like to know something else.
Best regards.