MailMerger.ExecuteWithRegions
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)
Parameter | Type | Description |
---|---|---|
inputFileName | String | The input file name. |
outputFileName | String | The output file name. |
dataTable | DataTable | Data 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
- class MailMerger
- namespace Wordize.MailMerging
- assembly Wordize
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)
Parameter | Type | Description |
---|---|---|
inputFileName | String | The input file name. |
outputFileName | String | The output file name. |
saveFormat | SaveFormat | The output’s save format. |
dataTable | DataTable | Table 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. |
mailMergeOptions | MailMergeOptions | Mail 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
- enum SaveFormat
- class MailMergeOptions
- class MailMerger
- namespace Wordize.MailMerging
- assembly Wordize
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)
Parameter | Type | Description |
---|---|---|
inputStream | Stream | The input file stream. |
outputStream | Stream | The output file stream. |
saveFormat | SaveFormat | The output’s save format. |
dataTable | DataTable | Table 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. |
mailMergeOptions | MailMergeOptions | Mail 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
- enum SaveFormat
- class MailMergeOptions
- class MailMerger
- namespace Wordize.MailMerging
- assembly Wordize
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)
Parameter | Type | Description |
---|---|---|
inputFileName | String | The input file name. |
outputFileName | String | The output file name. |
dataSet | DataSet | DataSet 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
- class MailMerger
- namespace Wordize.MailMerging
- assembly Wordize
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)
Parameter | Type | Description |
---|---|---|
inputFileName | String | The input file name. |
outputFileName | String | The output file name. |
saveFormat | SaveFormat | The output’s save format. |
dataSet | DataSet | DataSet that contains data to be inserted into mail merge fields. |
mailMergeOptions | MailMergeOptions | Mail 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
- enum SaveFormat
- class MailMergeOptions
- class MailMerger
- namespace Wordize.MailMerging
- assembly Wordize
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)
Parameter | Type | Description |
---|---|---|
inputStream | Stream | The input file stream. |
outputStream | Stream | The output file stream. |
saveFormat | SaveFormat | The output’s save format. |
dataSet | DataSet | DataSet that contains data to be inserted into mail merge fields. |
mailMergeOptions | MailMergeOptions | Mail 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
- enum SaveFormat
- class MailMergeOptions
- class MailMerger
- namespace Wordize.MailMerging
- assembly Wordize