How to Apply Custom Formatting during Mail Merge

[ ]

The MailMerge class provides two events that could be very useful in expanding mail merge capabilities. The setFieldMergingCallback(IFieldMergingCallback) property accepts a class which implements the methods fieldMerging(FieldMergingArgs) and imageFieldMerging(ImageFieldMergingArgs). These can be used to implement custom control over the mail merge process.

The fieldMerging(FieldMergingArgs) event occurs during mail merge when a simple mail merge field is encountered in the document. This gives further control over the mail merge and you can perform any actions when the event occurs. This method is wrapped in a class that implements the IFieldMergingCallBack interface and accepts a FieldMergingArgs object that provides data for the corresponding event.

The code example given below demonstrates how to implement custom logic in the MergeField event to apply cell formatting.