Mail Merge Format Issue- after aspose.words upgradation 9.8 to 15.2

Hello Team,

Recently we migrated from Aspose.Words version 9.8 to 15.2 for one of the pdf conversion issue. This went live few months back. As an impact, mail merge formatting which were supported earlier are not working in the new version of the dll.

Two issues:

  1. For some of the formats, Mailmerge.Execute() is not applying the values and returning blank.
  2. For some of the formats, an additional space is added between $ and the value.

Attaching the example project for the same. We have lot of documents which are critical in production having this issue.

I tried using trial version 15.6 as well and this issue doesnt seem to have fixed.

Kindly reply asap pls.

Hi there,

Thanks for your inquiry. Firstly, I suggest you please upgrade to the latest version of Aspose.Words for .NET 15.6.0 from here:
https://releases.aspose.com/words/net

Secondly, please note that Aspose.Words mimics the same behavior as MS Word does. If you perform the same mail merge operation with same values using MS Word, you will get the same output. See the attached image for detail.

Please remove the “* MERGEFORMAT” , “* Upper” and “* Lower” from mail merge fields and set the number formatting as # “$#,#0.00”. This will fix the issue which you are facing. I have attached the modified input document and output document with this post for your kind reference.

Please let us know if you have any more queries.

Thanks for your inputs.

Can you please explain why these formats were allowed and merging was working in Aspose version 9.8? Can you confirm if it was a bug in that version?

We are having lot of documents (more than 100) that are using this format.

what would be your suggestion, how do we go about fixing them? Is it possible for you to provide an automated example of modifying the format in merge field using Aspose dll.

Hi there,

Thanks for your inquiry.

*Babu_MunavarBasha:

Can you please explain why these formats were allowed and merging was working in Aspose version 9.8? Can you confirm if it was a bug in that version?*

The behavior of older version of Aspose.Word is incorrect. This was a bug in older version and fixed in latest versions of Aspose.Wods.

Please note that Aspose.Words mimics the same behavior as MS Word does.
If you perform the same mail merge operation with same values using MS
Word, you will get the same output.

*Babu_MunavarBasha:

what would be your suggestion, how do we go about fixing them? Is it possible for you to provide an automated example of modifying the format in merge field using Aspose dll.*

In this case, you need to remove the mail merge fields which contain number formatting and insert it again at same position with mail merge field name and number formatting. Please check following code example for your kind reference. Hope this helps you. I have attached the output document with this post for your kind reference.

DataTable table = new DataTable();
table.Columns.Add("ServiceID", typeof(string));
table.Columns.Add("TenantName", typeof(string));
table.Columns.Add("TenancyStartDate", typeof(DateTime));
table.Columns.Add("TotalServiceCharge", typeof(decimal));
table.Columns.Add("BulkEnergyCharge", typeof(decimal));
table.Columns.Add("BulkWaterCharge", typeof(decimal));
table.Rows.Add("1234567890", "Aspose", DateTime.Now, 500.07, 600.80, 700.36);
Document doc = new Document(MyDir + @"$ Scenario Replication.doc");
DocumentBuilder builder = new DocumentBuilder(doc);
foreach (Field field in doc.Range.Fields)
{
    if (field.Type == FieldType.FieldMergeField && field.GetFieldCode().Contains(@"\#"))
    {
        String[] numberformat = field.GetFieldCode().Replace(@"\*", "").Replace("MERGEFORMAT", "").Replace("MERGEFIELD", "").
        Replace("Upper", "").Replace("Lower", "").Trim().Split(' ');
        numberformat = numberformat.Where(val => val != "").ToArray();
        if (numberformat.Length > 1)
        {
            Console.WriteLine(field.GetFieldCode());
            String mailmerge = "MERGEFIELD ";
            foreach (String item in new ArrayList(numberformat))
            {
                mailmerge += " " + item;
            }
            builder.MoveToField(field, true);
            builder.InsertField(mailmerge);
            field.Remove();
            Console.WriteLine(mailmerge);
        }
    }
}
doc.MailMerge.Execute(table);
doc.Save(MyDir + "Out.doc");

I am impressed with the prompt response in detail. Thanks for the support.

I will try it out and get back incase if have some issues.

Hi there,

Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.