Problem showing Bold Merge fields in a Paragraph

Hi Aspose,

i m stuck with a problem that while inserting the merge field in a word template i am marking it as Bold…

when in my code(C#) i replace it with the value the field loses its formatting(Bold) and appears as normal text whereas it should be bold.

can u please guide me on this .

Thanks

DevCPP

Hi Aspose,
i m stuck with a problem that while inserting the merge field in a word template i am marking it as Bold…
when in my code i replace it with the value the field loses its formatting(Bold) and appears as normal text where as it should be bold.
can u please guide me on this .
I am also posting the question in forums just in case some other may answer thie.
Thanks
DevCPP

This message was posted using Aspose.Live 2 Forum

Hello,
Thank you for your inquiry.
Could you please attach your source document and a simple test application, or an example of code used, which could simulate the problem. I will analyze the issue and provide you more detailed information.

Hi there,
Thanks for your inquiry.
Please ensure you are inserting the field using the MERGEFORMAT switch. This switch causes the formatting on the original field to be carried over to the merged result.

builder.InsertField(@"MERGEFIELD MyField \* MERGEFORMAT");

Thanks,

hi Adam,Viktor

i have a sample template attached with this post.Its Name is MasterLetter.rtf.

u must be able to see the Bold and Colored Merge Codes.

but when i expand it using the following code the merge code styles are lost for first sentence ie where there are other styles in the sentence.
whereas «OfficeName» retains** style as it is the only word in that sentence.

can u help me on this.

DocumentBuilder builder = new DocumentBuilder(docsrc);
string fieldname = fieldnames[1]; //fieldNames Array contains all the Mergecode Names
bool found = builder.MoveToMergeField(fieldname);

while (found)
{
    Paragraph pg = builder.CurrentParagraph;
    if (pg != null)
    {
        if (!pg.IsInCell)
        {
            Font fnt = pg.ParagraphBreakFont;
            builder.Font.Name = SrcFont.Name;
            builder.Font.LocaleId = SrcFont.LocaleId;
            builder.Font.LocaleIdFarEast = SrcFont.LocaleIdFarEast;
            builder.Font.NameAscii = SrcFont.NameAscii;
            builder.Font.Bold = SrcFont.Bold;
            builder.Font.Color = SrcFont.Color;
            builder.Font.Italic = SrcFont.Italic;
        }
    }

    try
    {

        string fieldvalue = (string) fieldvalues[i];
        builder.Write(fieldvalue);

    }
    catch (Exception ex)
    {}

Hi
Thank you for additional information. Why do not you use Mail Merge feature to fill mergefields with data. Please see the following link and the code below:
https://docs.aspose.com/words/net/types-of-mail-merge-operations/

// Open a template.
Document doc = new Document(@"Test001\MasterLetter.rtf");
// Execute mail merge.
doc.MailMerge.Execute(new string[]
    {
        "FLName",
        "FName",
        "OfficeName"
    },
    new object[]
    {
        "testFLName",
        "testFName",
        "testOfficeName"
    });
// Save output.
doc.Save(@"Test001\out.rtf");

If fill your document with data using this code formatting of values is correct.
Best regards,