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.