Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7849601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:34:36+00:00 2026-06-02T18:34:36+00:00

We are using the Aspose.Words for .NET to export Word documents in our application.

  • 0

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)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T18:34:38+00:00Added an answer on June 2, 2026 at 6:34 pm

    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):

    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);
    

    You need to Implement IFieldMergingCallback interface to be able to control how data is inserted into merge fields during a mail merge operation.

    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); 
    

    I hope this is going to help in your scenario. If it doesn’t help, please do let me know.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my asp.net application, I am using Aspose.PDF for merging 2 pdf documents. I
I have a C# .Net web app using MVC3. I am using Aspose.Words to
I'm using Aspose to handle PDFs and Word documents. Each time I'm about to
I have a C# .Net web app using MVC3. I am using Aspose to
Using C# for ASP.NET and MOSS development, we often have to embed JavaScript into
We're using aspose.word to create a report from a word template direct to PDF
I am using Aspose.Cells and I have created a Range of cells. This range
I'm creating a newspaper authoring system. Today I'm using Aspose.Words library to generate newspaper
I have a web app that needs to be able to convert word documents
Using aspose, I have converted the first page of a pdf document to a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.