Mergefield And If-Condition


#1

Dear Support

I’m just evaluating Aspose.Word and have experienced some trouble with conditional mergefields.

I’m trying to populate a .dot containing mergefields that are dependant on an if-condition, e.g. if value of mergefield “ContactType” = ‘Company’ then the Label for the field signature should read ‘On behalf of ABC Inc’ else ‘John Smith’. It appears that these labels, which are not fields directly mapped to fields in the datareader but dependant on information contained in datareader fields, are ignored when the merge is performed. Is there any way to get this done?

Thanks very much for your efforts!


#2

Hi Martin,

Aspose.Word does not evaluate fields so conditional fields will not during mail merge like this.

If you want to apply some logic during mail merge, you need to attach a handler to MailMerge.MergeField event and execute your conditional logic there, inside the handler.

There are some examples in the forums:
http://www.aspose.com/forums/ShowPost.aspx?PostID=11282
http://www.aspose.com/forums/ShowPost.aspx?PostID=6120