We are using the Aspose.Words for .NET to export Word documents in our application.
Now I have to include RichText content (actually, a FlowDocument) in the exported document too.
In order to export, we are implementing the IMailMergeDataSource interface. The GetValue function of this IMailMergeDataSource implementation is called by the Aspose library, and this function is looks like this:
public override bool GetValue(string fieldName, out object fieldValue) { ... }
So I get the field name of the current field in the Word template, and I have to set the fieldValue to a string, so that the string in the fieldValue can appear in the Word document.
But for example when I set the fieldValue to a FlowDocument, the result will be an XML string (the ToString representation of the FlowDocument object)
I would suggest that you pass the rich text in the fieldValue. Load this rich text into Aspose.Words Document object as follows (within FieldMerging event):
You need to Implement IFieldMergingCallback interface to be able to control how data is inserted into merge fields during a mail merge operation.
I hope this is going to help in your scenario. If it doesn’t help, please do let me know.