MailMerger.Execute

MailMerger Execute method. Performs a mail merge operation for a single record.

Execute(string, string, string[], object[])

Performs a mail merge operation for a single record.

public static void Execute(string inputFileName, string outputFileName, string[] fieldNames, 
    object[] fieldValues)
ParameterTypeDescription
inputFileNameStringThe input file name.
outputFileNameStringThe output file name.
fieldNamesString[]Array of merge field names. Field names are not case sensitive. If a field name that is not found in the document is encountered, it is ignored.
fieldValuesObject[]Array of values to be inserted into the merge fields. Number of elements in this array must be the same as the number of elements in fieldNames.

Remarks

If the output format is an image (BMP, EMF, EPS, GIF, JPEG, PNG, or WebP), each page of the output will be saved as a separate file. The specified output file name will be used to generate file names for each part following the rule: outputFile_partIndex.extension.

If the output format is TIFF, the output will be saved as a single multi-frame TIFF file.

Examples

Shows how to fill template with data by executing simple mail merge with arrays data source.

string[] names = new string[] { "FirstName", "SecondName", "Position" };
string[] values = new string[] { "James", "Bond", "Spy" };

MailMerger.Execute(MyDir + "MailMergeTemplate.docx", ArtifactsDir + "MailMerger.Execute.docx", names, values);

See Also


Execute(string, string, SaveFormat, string[], object[], MailMergeOptions)

Performs a mail merge operation for a single record.

public static void Execute(string inputFileName, string outputFileName, SaveFormat saveFormat, 
    string[] fieldNames, object[] fieldValues, MailMergeOptions mailMergeOptions = null)
ParameterTypeDescription
inputFileNameStringThe input file name.
outputFileNameStringThe output file name.
saveFormatSaveFormatThe output’s save format.
fieldNamesString[]Array of merge field names. Field names are not case sensitive. If a field name that is not found in the document is encountered, it is ignored.
fieldValuesObject[]Array of values to be inserted into the merge fields. Number of elements in this array must be the same as the number of elements in fieldNames.
mailMergeOptionsMailMergeOptionsMail merge options.

Remarks

If the output format is an image (BMP, EMF, EPS, GIF, JPEG, PNG, or WebP), each page of the output will be saved as a separate file. The specified output file name will be used to generate file names for each part following the rule: outputFile_partIndex.extension.

If the output format is TIFF, the output will be saved as a single multi-frame TIFF file.

Examples

Shows how to fill template with data by executing simple mail merge with arrays data source with mail merge options.

string[] names = new string[] { "FirstName", "SecondName", "Position" };
string[] values = new string[] { "    James    ", "Bond", "      Spy" };

MailMergeOptions mailMergeOptions = new MailMergeOptions();
// Instruct Wordize to avoid trimming whitespace in field values.
mailMergeOptions.TrimWhitespaces = false;

MailMerger.Execute(MyDir + "MailMergeTemplate.docx", ArtifactsDir + "MailMerger.Execute.pdf", SaveFormat.Pdf, names, values, mailMergeOptions);

See Also


Execute(Stream, Stream, SaveFormat, string[], object[], MailMergeOptions)

Performs a mail merge operation for a single record.

public static void Execute(Stream inputStream, Stream outputStream, SaveFormat saveFormat, 
    string[] fieldNames, object[] fieldValues, MailMergeOptions mailMergeOptions = null)
ParameterTypeDescription
inputStreamStreamThe input file stream.
outputStreamStreamThe output file stream.
saveFormatSaveFormatThe output’s save format.
fieldNamesString[]Array of merge field names. Field names are not case sensitive. If a field name that is not found in the document is encountered, it is ignored.
fieldValuesObject[]Array of values to be inserted into the merge fields. Number of elements in this array must be the same as the number of elements in fieldNames.
mailMergeOptionsMailMergeOptionsMail merge options.

Remarks

If the output format is an image (BMP, EMF, EPS, GIF, JPEG, PNG, or WebP), only the first page of the output will be saved to the specified stream.

If the output format is TIFF, the output will be saved as a single multi-frame TIFF to the specified stream.

Examples

Shows how to fill template loaded from stream with data by executing simple mail merge with arrays data source.

string[] names = new string[] { "FirstName", "SecondName", "Position" };
string[] values = new string[] { "James", "Bond", "Spy" };

using (Stream input = File.OpenRead(MyDir + "MailMergeTemplate.docx"))
using (Stream output = File.Create(ArtifactsDir + "MailMerger.Execute.xps"))
{
    MailMerger.Execute(input, output, SaveFormat.Xps, names, values);
}

See Also


Execute(string, string, DataRow)

Performs mail merge from a DataRow into the document.

public static void Execute(string inputFileName, string outputFileName, DataRow dataRow)
ParameterTypeDescription
inputFileNameStringThe input file name.
outputFileNameStringThe output file name.
dataRowDataRowRow that contains data to be inserted into mail merge fields. Field names are not case sensitive. If a field name that is not found in the document is encountered, it is ignored.

Remarks

If the output format is an image (BMP, EMF, EPS, GIF, JPEG, PNG, or WebP), each page of the output will be saved as a separate file. The specified output file name will be used to generate file names for each part following the rule: outputFile_partIndex.extension.

If the output format is TIFF, the output will be saved as a single multi-frame TIFF file.

Examples

Shows how to fill template with data by executing simple mail merge with DataRow data source.

DataTable dt = new DataTable();
dt.Columns.Add("FirstName");
dt.Columns.Add("SecondName");
dt.Columns.Add("Position");
DataRow dr = dt.Rows.Add("James", "Bond", "Spy");

MailMerger.Execute(MyDir + "MailMergeTemplate.docx", ArtifactsDir + "MailMerger.Execute.DataRow.docx", dr);

See Also


Execute(string, string, SaveFormat, DataRow, MailMergeOptions)

Performs mail merge from a DataRow into the document.

public static void Execute(string inputFileName, string outputFileName, SaveFormat saveFormat, 
    DataRow dataRow, MailMergeOptions mailMergeOptions = null)
ParameterTypeDescription
inputFileNameStringThe input file name.
outputFileNameStringThe output file name.
saveFormatSaveFormatThe output’s save format.
dataRowDataRowRow that contains data to be inserted into mail merge fields. Field names are not case sensitive. If a field name that is not found in the document is encountered, it is ignored.
mailMergeOptionsMailMergeOptionsMail merge options.

Remarks

If the output format is an image (BMP, EMF, EPS, GIF, JPEG, PNG, or WebP), each page of the output will be saved as a separate file. The specified output file name will be used to generate file names for each part following the rule: outputFile_partIndex.extension.

If the output format is TIFF, the output will be saved as a single multi-frame TIFF file.

Examples

Shows how to fill template with data by executing simple mail merge with DataRow data source with mail merge options.

DataTable dt = new DataTable();
dt.Columns.Add("FirstName");
dt.Columns.Add("SecondName");
dt.Columns.Add("Position");
DataRow dr = dt.Rows.Add("James", "Bond", "");

MailMergeOptions mailMergeOptions = new MailMergeOptions();
// Instruct Wordize to remove empty paragraphs produced upon executing mail merge.
mailMergeOptions.CleanupOptions = MailMergeCleanupOptions.RemoveEmptyParagraphs;

MailMerger.Execute(MyDir + "MailMergeTemplate.docx", ArtifactsDir + "MailMerger.Execute.DataRow.pdf", SaveFormat.Pdf, dr, mailMergeOptions);

See Also


Execute(Stream, Stream, SaveFormat, DataRow, MailMergeOptions)

Performs a mail merge operation for a single record.

public static void Execute(Stream inputStream, Stream outputStream, SaveFormat saveFormat, 
    DataRow dataRow, MailMergeOptions mailMergeOptions = null)
ParameterTypeDescription
inputStreamStreamThe input file stream.
outputStreamStreamThe output file stream.
saveFormatSaveFormatThe output’s save format.
dataRowDataRowRow that contains data to be inserted into mail merge fields. Field names are not case sensitive. If a field name that is not found in the document is encountered, it is ignored.
mailMergeOptionsMailMergeOptionsMail merge options.

Remarks

If the output format is an image (BMP, EMF, EPS, GIF, JPEG, PNG, or WebP), only the first page of the output will be saved to the specified stream.

If the output format is TIFF, the output will be saved as a single multi-frame TIFF to the specified stream.

Examples

Shows how to fill template loaded from stream with data by executing simple mail merge with DataRow data source.

DataTable dt = new DataTable();
dt.Columns.Add("FirstName");
dt.Columns.Add("SecondName");
dt.Columns.Add("Position");
DataRow dr = dt.Rows.Add("James", "Bond", "Spy");

using (Stream input = File.OpenRead(MyDir + "MailMergeTemplate.docx"))
using (Stream output = File.Create(ArtifactsDir + "MailMerger.Execute.DataRow.xps"))
{
    MailMerger.Execute(input, output, SaveFormat.Xps, dr);
}

See Also


Execute(string, string, DataTable)

Performs mail merge from a DataTable into the document.

public static void Execute(string inputFileName, string outputFileName, DataTable dataTable)
ParameterTypeDescription
inputFileNameStringThe input file name.
outputFileNameStringThe output file name.
dataTableDataTableTable that contains data to be inserted into mail merge fields. Field names are not case sensitive. If a field name that is not found in the document is encountered, it is ignored.

Remarks

If the output format is an image (BMP, EMF, EPS, GIF, JPEG, PNG, or WebP), each page of the output will be saved as a separate file. The specified output file name will be used to generate file names for each part following the rule: outputFile_partIndex.extension.

If the output format is TIFF, the output will be saved as a single multi-frame TIFF file.

Examples

Shows how to fill template with data by executing simple mail merge with DataTable data source.

DataTable dt = new DataTable();
dt.Columns.Add("FirstName");
dt.Columns.Add("SecondName");
dt.Columns.Add("Position");
dt.Rows.Add("James", "Bond", "Spy");
dt.Rows.Add("John", "Doe", "Unknown");

MailMerger.Execute(MyDir + "MailMergeTemplate.docx", ArtifactsDir + "MailMerger.Execute.DataTable.docx", dt);

See Also


Execute(string, string, SaveFormat, DataTable, MailMergeOptions)

Performs mail merge from a DataRow into the document.

public static void Execute(string inputFileName, string outputFileName, SaveFormat saveFormat, 
    DataTable dataTable, MailMergeOptions mailMergeOptions = null)
ParameterTypeDescription
inputFileNameStringThe input file name.
outputFileNameStringThe output file name.
saveFormatSaveFormatThe output’s save format.
dataTableDataTableTable that contains data to be inserted into mail merge fields. Field names are not case sensitive. If a field name that is not found in the document is encountered, it is ignored.
mailMergeOptionsMailMergeOptionsMail merge options.

Remarks

If the output format is an image (BMP, EMF, EPS, GIF, JPEG, PNG, or WebP), each page of the output will be saved as a separate file. The specified output file name will be used to generate file names for each part following the rule: outputFile_partIndex.extension.

If the output format is TIFF, the output will be saved as a single multi-frame TIFF file.

Examples

Shows how to fill template with data by executing simple mail merge with DataTable data source with mail merge options.

DataTable dt = new DataTable();
dt.Columns.Add("FirstName");
dt.Columns.Add("SecondName");
dt.Columns.Add("Position");
dt.Rows.Add("James", "Bond", "Spy");
dt.Rows.Add("John", "Doe", "Unknown");

MailMergeOptions mailMergeOptions = new MailMergeOptions();
mailMergeOptions.RetainFirstSectionStart = false;

MailMerger.Execute(MyDir + "MailMergeTemplate.docx", ArtifactsDir + "MailMerger.Execute.DataTable.pdf", SaveFormat.Pdf, dt, mailMergeOptions);

See Also


Execute(Stream, Stream, SaveFormat, DataTable, MailMergeOptions)

Performs a mail merge operation for a single record.

public static void Execute(Stream inputStream, Stream outputStream, SaveFormat saveFormat, 
    DataTable dataTable, MailMergeOptions mailMergeOptions = null)
ParameterTypeDescription
inputStreamStreamThe input file stream.
outputStreamStreamThe output file stream.
saveFormatSaveFormatThe output’s save format.
dataTableDataTableTable that contains data to be inserted into mail merge fields. Field names are not case sensitive. If a field name that is not found in the document is encountered, it is ignored.
mailMergeOptionsMailMergeOptionsMail merge options.

Remarks

If the output format is an image (BMP, EMF, EPS, GIF, JPEG, PNG, or WebP), only the first page of the output will be saved to the specified stream.

If the output format is TIFF, the output will be saved as a single multi-frame TIFF to the specified stream.

Examples

Shows how to fill template loaded from stream with data by executing simple mail merge with DataTable data source.

DataTable dt = new DataTable();
dt.Columns.Add("FirstName");
dt.Columns.Add("SecondName");
dt.Columns.Add("Position");
dt.Rows.Add("James", "Bond", "Spy");
dt.Rows.Add("John", "Doe", "Unknown");

using (Stream input = File.OpenRead(MyDir + "MailMergeTemplate.docx"))
using (Stream output = File.Create(ArtifactsDir + "MailMerger.Execute.DataTable.xps"))
{
    MailMerger.Execute(input, output, SaveFormat.Xps, dt);
}

See Also