Mail Merge

  • 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 in each document. This feature can be useful for a variety of business requirements, such as personalized letters, and composing catalogs and reports.

IMPORTANT

The WPF Spreadsheet does not provide mail-merge UI tools (like the WinForms SpreadsheetControl) allowing end-users to design templates, bind them to data sources and preview mail merge results. However, you can generate mail-merge documents in code using the control's API as shown in the How to: Perform a Mail Merge example.

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 is 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 is merged into a template's fields in merged documents. A data source can be any object that exposes the IList interface, such as a ArrayList or a DataTable. You can create a mail merge data source at runtime or retrieve data from an external database using data adapters.

    The data source is bound to the template using the template workbook's IWorkbook.MailMergeDataSource and IWorkbook.MailMergeDataMember properties.

Use the template workbook's IWorkbook.MailMergeOptions property to get access to the mail merge options.

The template workbook's IWorkbook.GenerateMailMergeDocuments method finalizes the mail merging process. It returns a collection of resulting workbooks (if the Single Sheet or Multiple Sheets mail merge mode is used, the collection contains a single workbook). You can open the resulting workbook or save it to a file or stream.

See Also