We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Mail merge with bad formula

When executing a word merge via aspose.words is there a way to capture an error that occurs due to a malformed IF statement in the word file?

Right now the merge completes and the output displays something like “Error! Unknown op code for conditional”.

We’d like to capture this error and handle within the program that is running the mail merge.

Thanks,
Paul

@Paul.D.McDonald

You can check the result of IF field by Field.Result property after performing mail merge.

Thank you for the response.

Is there a way to perform the check on a document level? For example if any IF field in the document resulted in an error we could check something like document.Result without having to iterate through all of the fields and checking each result.

Thanks,
Paul

@Paul.D.McDonald

Unfortunately, there is no other way to get IF field that returns error message. You may use following code example. Hope this helps you.

Document doc = new Document(MyDir + "in.docx");
foreach (FieldIf field in doc.Range.Fields.Cast<FieldIf>().Where(field => field.Type == FieldType.FieldIf && field.Result.Contains("Error")))
{ 

}