/// <summary> /// 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. /// </summary> /// <param name="doc">The document containing unused regions</param> /// <param name="handler">The handler which implements the IFieldMergingCallback interface and defines the logic to be applied to each unmerged region.</param> /// <param name="regionsList">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.</param> 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 //ExStart //ExId:ExecuteCustomLogicOnEmptyRegionsMethod //ExSummary:Shows how to execute custom logic on unused regions using the specified handler. /// <summary> /// Applies logic defined in the passed handler class to all unused regions in the document. This allows to manually control /// how unused regions are handled in the document. /// </summary> /// <param name="doc">The document containing unused regions</param> /// <param name="handler">The handler which implements the IFieldMergingCallback interface and defines the logic to be applied to each unmerged region.</param> public static void ExecuteCustomLogicOnEmptyRegions(Document doc, IFieldMergingCallback handler) { ExecuteCustomLogicOnEmptyRegions(doc, handler, null); // Pass null to handle all regions found in the document. }