Aspose.Words.Examples.CSharp.Mail_Merge.ApplyCustomLogicToEmptyRegions.ExecuteCustomLogicOnEmptyRegions C# (CSharp) Method

ExecuteCustomLogicOnEmptyRegions() public static method

Applies logic defined in the passed handler class to specific unused regions in the document as defined in regionsList. This allows to manually control How unused regions are handled in the document.
public static ExecuteCustomLogicOnEmptyRegions ( Document doc, IFieldMergingCallback handler, ArrayList regionsList ) : void
doc Document The document containing unused regions
handler IFieldMergingCallback The handler which implements the IFieldMergingCallback interface and defines the logic to be applied to each unmerged region.
regionsList System.Collections.ArrayList A list of strings corresponding to the region names that are to be handled by the supplied handler class. Other regions encountered will not be handled and are removed automatically.
return void
        public static void ExecuteCustomLogicOnEmptyRegions(Document doc, IFieldMergingCallback handler, ArrayList regionsList)
        {
            // Certain regions can be skipped from applying logic to by not adding the table name inside the CreateEmptyDataSource method.
            // Enable this cleanup option so any regions which are not handled by the user's logic are removed automatically.
            doc.MailMerge.CleanupOptions = MailMergeCleanupOptions.RemoveUnusedRegions;

            // Set the user's handler which is called for each unmerged region.
            doc.MailMerge.FieldMergingCallback = handler;

            // Execute mail merge using the dummy dataset. The dummy data source contains the table names of 
            // Each unmerged region in the document (excluding ones that the user may have specified to be skipped). This will allow the handler 
            // To be called for each field in the unmerged regions.
            doc.MailMerge.ExecuteWithRegions(CreateDataSourceFromDocumentRegions(doc, regionsList));
        }
        // ExEnd:ExecuteCustomLogicOnEmptyRegions

Same methods

ApplyCustomLogicToEmptyRegions::ExecuteCustomLogicOnEmptyRegions ( Document doc, IFieldMergingCallback handler ) : void