Free Support Forum -

Sophisticated IF Field Condition CANNOT BE Parsed Correctly!


Currently we use Aspose.Words 13.2.0 in our system and today I found an issue that in this version, the sophisticated IF field condition cannot be parsed correctly which will give us “!Syntax Error” if you don’t PRESS F9 to update it manually!

In the attached document, the if field is “{ IF { = AND({Compare {MERGFIELD F1} = true}, {Compare {MERGEFIELD F2} = true})} = 1 “Combination Condition is True” “False” }”.
If in code I give true to both F1 and F2, in generated document, the expression result will still be “False”, not “Combination Condition is True”, unless you update it manually!

I remember in 9.2.0, it should work fine. So could anybody help me to look into the issue using 13.2.0?

Another thing to pay attention is for Aspose upgrade this year, we’ve tested Aspose.Words 13.2.0 for a couple of weeks because it is used in a lot of places of our system. So I’m afraid we cannot accept the simple version upgrade if you suggest because it will spend a lot of time to test in our system again! If you can confirm it is issue of 13.2.0, I could suggest our users using other simple IF condition instead.


Hi Sheng,

Thanks for your inquiry. I have tested the scenario with latest version of Aspose.Words 13.4.0 and 13.2.0 and have not found the shared issue. I would suggest you please upgrade to the latest version (v13.4.0) from here and let us know how it goes on your side. If the problem still remains, please share following details for investigation purposes.

What environment are you running on?

  • OS (Windows Version or Linux Version)
  • Architecture (32 / 64 bit)
  • .NET Framework version
  • Provide information about your specific culture, such as the name of the culture, language and country/region.
  • Please supply us with the code from your application that is causing the issue
  • Please supply us with the output document showing the undesired behaviour


I think you give me an important hint: culture. Yes, that document is generated under “de-DE” because that issue was found during Germany report test. I had tried document generation under “en-US” and the result is correct. So did you test 13.2.0 or 13.4.0 under non-“en-US” culture? Anyway, now using latest version of Aspose.Words is not our option because deadline of our project is coming and team won’t give me enough time to test this latest version of Aspose.Words, because 30+ word templates of different countries will be used to generate report, and some of them have 100+ pages. It is really huge workload. Now I found a solution to resolve it:

Dictionary<string, object> dic = new Dictionary<string, object>();
dic[“F1”] = true;
dic[“F2”] = true;
doc.MailMerge.Execute(dic.Keys.ToArray(), dic.Values.ToArray());

protected override void UpdateFields(Document doc)
var currentCulture = Thread.CurrentThread.CurrentCulture;
if (currentCulture.Name == “de-DE”)
Thread.CurrentThread.CurrentCulture = new CultureInfo(“en-US”);

foreach (var ifField in doc.Range.Fields.Cast().Where(f => f.Type == FieldType.FieldIf && ContainsAndOrFormula(f)))

Thread.CurrentThread.CurrentCulture = currentCulture;

private bool ContainsAndOrFormula(Field field)
string ifParam = string.Concat(field.Start.ParentParagraph.Runs.Cast().Select(r => r.Text)).Replace(" “, string.Empty);
return (ifParam.Contains(”=AND(") || ifParam.Contains("=OR("));

I’ve tested it and confirmed it could resolve the issue temporarily. If you have better solutions please let me know.


I found under “en-CA”, that IF Field can also be parsed correctly. So does it mean your parsing engine can process correctly under English environment?

Hi Sheng,

Thanks for sharing the details. Firstly, I suggest you please read following documentation link for your kind reference.

Secondly, I like to share with you that Aspose.Words correctly updating the Fields. The problem you are facing due to the Culture difference. Under “de-DE” the list separator is ; (semi colon) not , (comma). Please see the attached Image for detail. I have modified your document for your kind reference and have attached to this post.

In your case, I suggest you please use FieldUpdateCultureSource.FieldCode to get the desired output or you may modify your template document (see the attached Docx files). Please see the syntax of =AND in attached document.

Document doc = new
Document(MyDir + “in.doc”);<o:p></o:p>

doc.FieldOptions.FieldUpdateCultureSource = FieldUpdateCultureSource.FieldCode;


new string[] { "F1", "F2" },

new object[] { "True", "True" });

doc.Save(MyDir + "out.docx");