Mail Merge Overview
- 2 minutes to read
The Mail Merge functionality enables you to automatically generate a set of documents based on a single template and include unique data values retrieved from a data source into each document. This feature can be useful for a variety of business requirements, such as personalizing letters, and composing catalogs and reports.
This document contains an overview of the mail merge process and lists special mail merge tools provided by SpreadsheetControl.
Mail Merge Process
To perform a mail merge, you need a template and a data source.
- A template is a document containing placeholders for the information that will be merged from a data source (mail merge fields). See the Template Document topic to learn more about mail merge templates.
A data source contains data that will be merged into fields in a template to create merged documents. A data source can be any object that exposes the IList interface, such as a ArrayList or a DataTable. So, you can create a mail merge data source at runtime, or retrieve data from an external database via corresponding data adapters.
Loading the mail merge templates with the ObjectDataSource data source may be unsafe if the data source is contained in a compiled assembly. Use the SpreadsheetControlOptions.DataSourceOptions property and a custom service that implements the IObjectDataSourceValidationService interface to validate an ObjectDataSource contained in the loaded document and prevent the data source from loading.
Use the template workbook’s IWorkbook.MailMergeOptions property to get access to the mail merge options.
The IWorkbook.GenerateMailMergeDocuments method of the template workbook finalizes the mail merge process. It returns a collection of resulting workbooks (if the Single Sheet or Multiple Sheets mail merge mode is used, the collection will contain a single workbook). You can open the resulting workbook in a SpreadsheetControl instance, or save it to a file or stream.
The Mail Merge section contains step-by-step tutorials on how to use the SpreadsheetControl’s mail merge functionality.
SpreadsheetControl’s Mail Merge Tools
SpreadsheetControl provides a set of easy-to-use tools allowing your end-users to visually design templates and preview mail merge results on-the-fly.