Please help. I’m trying to diagnose a complex problem with mail merge fields inside conditional IF statements in Word templates created by our customers.
As a first step, I’m trying to create a POC that demonstrates the problem, however in my POC I can not get the IF statements to evaluate AT ALL. The basic mail merge works (most of the time) but the IF statements do NOTHING and come through unchanged
I’m using Aspose.Words v19.10 for .NET, building sample project against .NET framework 4.5.2.
What is wrong with this sample code?
// Load template
string dataDir = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
string inPath = Path.Combine(dataDir, "MergeMe.docx");
Document doc = new Document(inPath);
//doc.MailMerge.UseNonMergeFields = true; // INTERESTNG - See Aspose help
// Fill the fields in the document with user data.
doc.MailMerge.Execute(
new string[] { "Key1", "Key2", "Key3"},
new object[] { "Value1", "Value2", "Value3"});
string outPath = Path.Combine(dataDir, Path.GetFileNameWithoutExtension(inPath) + "_" + DateTime.Now.ToString("HHmmss") + ".docx");
doc.Save(outPath);
See attached output:
Template and Console App (without the license file) attached.
AsposePOC.zip (4.9 MB)