MailMerger.ExecuteWithRegions

MailMerger ExecuteWithRegions method. Performs mail merge from a DataTable into the document with mail merge regions.

ExecuteWithRegions(string, string, DataTable)

Performs mail merge from a DataTable into the document with mail merge regions.

public static void ExecuteWithRegions(string inputFileName, string outputFileName, 
    DataTable dataTable)
ParameterTypeDescription
inputFileNameStringThe input file name.
outputFileNameStringThe output file name.
dataTableDataTableData source for the mail merge operation. The table must have its TableName property set.

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 a template with data by executing mail merge with regions using a DataTable data source.

DataTable dt = new DataTable("Items");
dt.Columns.Add("Item");
dt.Columns.Add("Quantity");
dt.Columns.Add("Price");
dt.Rows.Add("Orange", 5, 10);
dt.Rows.Add("Apple", 10, 4);
dt.Rows.Add(null, null, null); // empty row.
dt.Rows.Add("Pear", 4, 6);

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

See Also


ExecuteWithRegions(string, string, SaveFormat, DataTable, MailMergeOptions)

Performs mail merge from a DataTable into the document with mail merge regions.

public static void ExecuteWithRegions(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 a template with data by executing mail merge with regions using a DataTable data source with mail merge options.

DataTable dt = new DataTable("Items");
dt.Columns.Add("Item");
dt.Columns.Add("Quantity");
dt.Columns.Add("Price");
dt.Rows.Add("Orange", 5, 10);
dt.Rows.Add("Apple", 10, 4);
dt.Rows.Add(null, null, null); // empty row.
dt.Rows.Add("Pear", 4, 6);

MailMergeOptions mailMergeOptions = new MailMergeOptions();
// Instruct Wordize to remove empty table rows produced upon executing mail merge with regions.
mailMergeOptions.CleanupOptions = MailMergeCleanupOptions.RemoveEmptyTableRows;

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

See Also


ExecuteWithRegions(Stream, Stream, SaveFormat, DataTable, MailMergeOptions)

Performs a mail merge operation for a single record.

public static void ExecuteWithRegions(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 a template loaded from stream with data by executing mail merge with regions using a DataTable data source.

DataTable dt = new DataTable("Items");
dt.Columns.Add("Item");
dt.Columns.Add("Quantity");
dt.Columns.Add("Price");
dt.Rows.Add("Orange", 5, 10);
dt.Rows.Add("Apple", 10, 4);
dt.Rows.Add(null, null, null); // empty row.
dt.Rows.Add("Pear", 4, 6);

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

See Also


ExecuteWithRegions(string, string, DataSet)

Performs mail merge from a DataSet into a document with mail merge regions.

public static void ExecuteWithRegions(string inputFileName, string outputFileName, DataSet dataSet)
ParameterTypeDescription
inputFileNameStringThe input file name.
outputFileNameStringThe output file name.
dataSetDataSetDataSet that contains data to be inserted into mail merge fields.

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 a template with data by executing mail merge with regions using a DataSet data source.

DataSet ds = new DataSet();
DataTable dt = ds.Tables.Add("Items");
dt.Columns.Add("Item");
dt.Columns.Add("Quantity");
dt.Columns.Add("Price");
dt.Rows.Add("Orange", 5, 10);
dt.Rows.Add("Apple", 10, 4);
dt.Rows.Add(null, null, null); // empty row.
dt.Rows.Add("Pear", 4, 6);

MailMerger.ExecuteWithRegions(MyDir + "MailMergeTemplate.docx", ArtifactsDir + "MailMerger.ExecuteWithRegions.DataSet.docx", ds);

See Also


ExecuteWithRegions(string, string, SaveFormat, DataSet, MailMergeOptions)

Performs mail merge from a DataTable into the document with mail merge regions.

public static void ExecuteWithRegions(string inputFileName, string outputFileName, 
    SaveFormat saveFormat, DataSet dataSet, MailMergeOptions mailMergeOptions = null)
ParameterTypeDescription
inputFileNameStringThe input file name.
outputFileNameStringThe output file name.
saveFormatSaveFormatThe output’s save format.
dataSetDataSetDataSet that contains data to be inserted into mail merge fields.
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 a template with data by executing mail merge with regions using a DataSet data source with mail merge options.

DataSet ds = new DataSet();
DataTable dt = ds.Tables.Add("Items");
dt.Columns.Add("Item");
dt.Columns.Add("Quantity");
dt.Columns.Add("Price");
dt.Rows.Add(null, null, null); // empty row.

MailMergeOptions mailMergeOptions = new MailMergeOptions();
mailMergeOptions.CleanupOptions = MailMergeCleanupOptions.RemoveEmptyTables | MailMergeCleanupOptions.RemoveEmptyTableRows;

MailMerger.ExecuteWithRegions(MyDir + "MailMergeTemplate.docx", ArtifactsDir + "MailMerger.ExecuteWithRegions.DataSet.pdf", SaveFormat.Pdf, ds, mailMergeOptions);

See Also


ExecuteWithRegions(Stream, Stream, SaveFormat, DataSet, MailMergeOptions)

Performs a mail merge operation for a single record.

public static void ExecuteWithRegions(Stream inputStream, Stream outputStream, 
    SaveFormat saveFormat, DataSet dataSet, MailMergeOptions mailMergeOptions = null)
ParameterTypeDescription
inputStreamStreamThe input file stream.
outputStreamStreamThe output file stream.
saveFormatSaveFormatThe output’s save format.
dataSetDataSetDataSet that contains data to be inserted into mail merge fields.
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 a template loaded from stream with data by executing mail merge with regions using a DataSet data source.

DataSet ds = new DataSet();
DataTable dt = ds.Tables.Add("Items");
dt.Columns.Add("Item");
dt.Columns.Add("Quantity");
dt.Columns.Add("Price");
dt.Rows.Add("Orange", 5, 10);
dt.Rows.Add("Apple", 10, 4);
dt.Rows.Add(null, null, null); // empty row.
dt.Rows.Add("Pear", 4, 6);

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

See Also