我建议您在 fieldValue 中传递富文本。将此富文本加载到 Aspose.Words Document 对象中,如下所示(在 FieldMerging 事件中):
string rtfStr = "{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang3079{\\fonttbl{\\f0\\fnil\\fcharset0 Microsoft Sans Serif;}}{\\colortbl ;\\red255\\green0\\blue0;\\red0\\green128\\blue0;\\red0\\green0\\blue255;}\\viewkind4\\uc1\\pard\\cf1\\f0\\fs17 Rot.\\cf0\\fs17 \\cf2\\fs17 Gr\\'fcn.\\cf0\\fs17 \\cf3\\fs17 Blau.\\cf0\\fs17 \\i\\fs17 Kursiv.\\i0\\fs17 \\strike\\fs17 Durchgestrichen. \\ul\\strike0 Unterstrichen.\\ulnone\\fs17 \\b\\fs17 Fett.\\b0\\fs17\\par}";
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
byte[] dataBytes = encoding.GetBytes(rtfStr);
MemoryStream stream = new MemoryStream(dataBytes);
LoadOptions loadOptions = new LoadOptions();
loadOptions.LoadFormat = LoadFormat.Rtf;
Document doc = new Document(stream, loadOptions);
您需要实现 IFieldMergingCallback 接口,以便能够控制在邮件合并操作期间如何将数据插入到合并字段中。
private class HandleMergeFields : IFieldMergingCallback
{
void IFieldMergingCallback.FieldMerging(FieldMergingArgs e)
{
DocumentBuilder builder = new DocumentBuilder(e.Document);
builder.MoveToMergeField("fieldName");
Node node = builder.CurrentNode;
// doc is an RTF document we created from RTF string
InsertDocument(node, doc);
我希望这对您的情况有所帮助。如果它没有帮助,请让我知道。