Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Wed Nov 08, 2023 9:00 am

Hi,

our client reported the following issue - when two identical merge fields are used in template the result is wrong.

In their case both fields are almost the same with only one different character - 't' at the end.

The template is attached.

Here is my code:

Code: Select all
static void merge()
{   
    var data = new DataTable();
    data.Columns.Add(new DataColumn("InvestorAccount_REPORTINGDistributionsto", typeof(decimal)));
    data.Columns.Add(new DataColumn("InvestorAccount_REPORTINGDistributionsTo", typeof(decimal)));

    var r = data.Rows.Add();
    r["InvestorAccount_REPORTINGDistributionsTo"] = 1.56;
    r["InvestorAccount_REPORTINGDistributionsto"] = 3.14;

    foreach (DataRow dr in data.Rows)
    {
        using (var document = new Doc.Document())
        {
            document.LoadFromFile(template);
            document.MailMerge.ClearFields = true;
            document.MailMerge.MergeField += MailMerge_MergeField;

            var resultFile = Path.GetTempFileName() + ".docx";

            document.MailMerge.Execute(dr);

            document.SaveToFile(resultFile);

            Process.Start(resultFile);
        }
    }
}

static void MailMerge_MergeField(object sender, Doc.Reporting.MergeFieldEventArgs args)
{
    var mergeField = args.CurrentMergeField as MergeField;
    var val = args.FieldValue as string; // Always empty

    Console.WriteLine($"{mergeField.FieldName} - {val}");
}


After merge both values are equal.

profiler007
 
Posts: 72
Joined: Wed Nov 13, 2019 11:32 am

Thu Nov 09, 2023 2:48 am

Hi,

Thanks for your feedback.
I have reproduced this issue and logged it into our issue tracking system with the ticket number SPIREDOC-10029, our dev team will investigate and fix it. We apologize for any inconvenience caused. Once the issue is fixed, I will inform you asap.

Best regards,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Wed Dec 13, 2023 7:45 am

Hi,

Thanks for your patience.
Glad to inform you that we just released Spire.Doc 11.12.2 hotfix, which has fixed your issue SPIREDOC-10029, please download from the following links and have a test.
Website: https://www.e-iceblue.com/Download/download-word-for-net-now.html
Nuget: https://www.nuget.org/packages/Spire.Doc/11.12.2

Best regards,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Return to Spire.Doc

cron