Represents the mail merge functionality.
For a list of all members of this type, see MailMerge Members.
System.Object
Aspose.Words.Reporting.MailMerge
[Visual Basic]
Public Class MailMerge
[C#]public class MailMerge
Remarks
For mail merge operation to work, the document should contain Word MERGEFIELD and optionally NEXT fields. During mail merge operation, merge fields in the document are replaced with values from your data source.
There are two distinct ways to use mail merge: with mail merge regions and without.
The simplest mail merge is without regions and it is very similar to how mail merge works in Word. Use Execute methods to merge information from some data source such as DataTable, DataView, IDataReader or an array of objects into your document. The MailMerge object processes all records of the data source and copies and appends content of the whole document for each record.
Note that when MailMerge object encounters a NEXT field, it selects next record in the data source and continues merging without copying any content.
Use ExecuteWithRegions methods to merge information into a document with mail merge regions defined. You can use DataSet, DataTable, DataView or IDataReader as data sources for this operation.
You need to use mail merge regions if you want to dynamically grow portions inside the document. Without mail merge regions whole document will be repeated for every record of the data source.
Example
Executes mail merge from an ADO.NET DataTable.
[C#]
Document doc = new Document(MyDir + "MailMerge.ExecuteDataTable.doc");
// This example creates a table, but you would normally load table from a database.
DataTable table = new DataTable("Test");
table.Columns.Add("CustomerName");
table.Columns.Add("Address");
table.Rows.Add(new object[] {"Thomas Hardy", "120 Hanover Sq., London"});
table.Rows.Add(new object[] {"Paolo Accorti", "Via Monte Bianco 34, Torino"});
// Field values from the table are inserted into the mail merge fields found in the document.
doc.MailMerge.Execute(table);
doc.Save(MyDir + "MailMerge.ExecuteDataTable Out.doc");[Visual Basic]
Dim doc As Document = New Document(MyDir & "MailMerge.ExecuteDataTable.doc")
' This example creates a table, but you would normally load table from a database.
Dim table As DataTable = New DataTable("Test")
table.Columns.Add("CustomerName")
table.Columns.Add("Address")
table.Rows.Add(New Object() {"Thomas Hardy", "120 Hanover Sq., London"})
table.Rows.Add(New Object() {"Paolo Accorti", "Via Monte Bianco 34, Torino"})
' Field values from the table are inserted into the mail merge fields found in the document.
doc.MailMerge.Execute(table)
doc.Save(MyDir & "MailMerge.ExecuteDataTable Out.doc")Requirements
Namespace: Aspose.Words.Reporting
Assembly: Aspose.Words (in Aspose.Words.dll)
See Also
MailMerge Members | Aspose.Words.Reporting Namespace | Document | MailMerge