Free Support Forum -

Conditional IF statements not evaluating in Aspose.Words MailMerge

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.
new string[] { “Key1”, “Key2”, “Key3”},
new object[] { “Value1”, “Value2”, “Value3”});

string outPath = Path.Combine(dataDir, Path.GetFileNameWithoutExtension(inPath) + “_” + DateTime.Now.ToString(“HHmmss”) + “.docx”);

See attached output:

Template and Console App (without the license file) attached. (4.9 MB)


We are working on your query and will get back to you soon.


It seems, Aspose.Words’ mail merge engine works in the following way:

  1. When IF field’s expression evaluates into True AND merge field is inside the ‘True Part’ of IF field, then merge field will be replaced by its Value.

  2. When IF field’s expression evaluates into False AND merge field is inside the ‘False Part’ of IF field, then merge field will be replaced by its Value.

However, we tested the scenario and have managed to reproduce the same problem on our end i.e. some merge fields nested inside IF fields are not getting replaced by their values. For the sake of any correction, we have logged this problem in our issue tracking system. The ID of this issue is WORDSNET-20008. We will further look into the details of this problem and will keep you updated on the status of linked issue. We apologize for your inconvenience.