Error while merging document having OR condition in If statement. "Index and length must refer to a location within the string. Parameter name: length"
my code is as given below
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Aspose.Words;
using System.Data;
using Aspose.Words.Reporting;
namespace AsposeConsoleApp
{
class Program
{
static void Main(string[] args)
{
License lic = new License();
lic.SetLicense(@“C:\Users\jm39360\Downloads\Aspose.Total.lic”);
Document doc = new Document(@“C:\Users\jm39360\Desktop\Approach2Template.dotx”);
DataTable data = GetmergeData();
doc.MailMerge.CleanupOptions = doc.MailMerge.CleanupOptions & ~MailMergeCleanupOptions.RemoveUnusedFields | ~MailMergeCleanupOptions.RemoveUnusedRegions
| ~MailMergeCleanupOptions.RemoveEmptyParagraphs | ~MailMergeCleanupOptions.RemoveContainingFields;
doc.MailMerge.ExecuteWithRegions(data);
doc.Save(“out.docx”);
}
private static DataTable GetmergeData()
{
DataTable table = new DataTable(“Customer”);
table.Columns.Add(“Currency”, typeof(string));
DataRow row = table.NewRow();
row[“Currency”] = “GBP”;
table.Rows.Add(row);
return table;
}
}
}
have valid Aspose.total license.
Red lined code gives error.
my template has simple text as given below:
{ MERGEFIELD TableStart:Customer}
{if { = OR({ COMPARE { MERGEFIELD Currencey } = “GBP”),{ COMPARE { MERGEFIELD Currencey } = “HKD”)} = 1 “test”}
{ MERGEFIELD TableEnd:Customer }