になります私はあなたがfieldValueの中にリッチテキストを渡すことを示唆しています。 (FieldMergingイベント内)は次のようAspose.WordsではDocumentオブジェクトには、このリッチテキストをロードします。
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);
これはあなたのシナリオで役立つことを望みます。それが助けにならないなら、私に知らせてください。
これは機能します。ありがとう!私は、FlowDocument文字列をRTF文字列に変換するだけでした: – asdfghjkl
var xamlString = "..."; var flowDocument = FlowDocumentService.GetFlowDocument(xamlString); string dataFormat = DataFormats.Rtf; var documentTextRange = new TextRange(flowDocument.ContentStart、flowDocument.ContentEnd); var stream = new MemoryStream(); documentTextRange.Save(stream、dataFormat); LoadOptions loadOptions = new LoadOptions(); loadOptions.LoadFormat = LoadFormat.Rtf; fieldValue =新しいドキュメント(stream、loadOptions); – asdfghjkl