MailMerger.Execute
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)
Parameter | Type | Description |
---|---|---|
inputFileName | String | The input file name. |
outputFileName | String | The output file name. |
fieldNames | String[] | 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. |
fieldValues | Object[] | 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
- class MailMerger
- namespace Wordize.MailMerging
- assembly Wordize
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)
Parameter | Type | Description |
---|---|---|
inputFileName | String | The input file name. |
outputFileName | String | The output file name. |
saveFormat | SaveFormat | The output’s save format. |
fieldNames | String[] | 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. |
fieldValues | Object[] | 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. |
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 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
- enum SaveFormat
- class MailMergeOptions
- class MailMerger
- namespace Wordize.MailMerging
- assembly Wordize
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)
Parameter | Type | Description |
---|---|---|
inputStream | Stream | The input file stream. |
outputStream | Stream | The output file stream. |
saveFormat | SaveFormat | The output’s save format. |
fieldNames | String[] | 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. |
fieldValues | Object[] | 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. |
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 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
- enum SaveFormat
- class MailMergeOptions
- class MailMerger
- namespace Wordize.MailMerging
- assembly Wordize
Execute(string, string, DataRow)
Performs mail merge from a DataRow into the document.
public static void Execute(string inputFileName, string outputFileName, DataRow dataRow)
Parameter | Type | Description |
---|---|---|
inputFileName | String | The input file name. |
outputFileName | String | The output file name. |
dataRow | DataRow | Row 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
- class MailMerger
- namespace Wordize.MailMerging
- assembly Wordize
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)
Parameter | Type | Description |
---|---|---|
inputFileName | String | The input file name. |
outputFileName | String | The output file name. |
saveFormat | SaveFormat | The output’s save format. |
dataRow | DataRow | Row 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 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
- enum SaveFormat
- class MailMergeOptions
- class MailMerger
- namespace Wordize.MailMerging
- assembly Wordize
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)
Parameter | Type | Description |
---|---|---|
inputStream | Stream | The input file stream. |
outputStream | Stream | The output file stream. |
saveFormat | SaveFormat | The output’s save format. |
dataRow | DataRow | Row 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 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
- enum SaveFormat
- class MailMergeOptions
- class MailMerger
- namespace Wordize.MailMerging
- assembly Wordize
Execute(string, string, DataTable)
Performs mail merge from a DataTable into the document.
public static void Execute(string inputFileName, string outputFileName, DataTable dataTable)
Parameter | Type | Description |
---|---|---|
inputFileName | String | The input file name. |
outputFileName | String | The output file name. |
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. |
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
- class MailMerger
- namespace Wordize.MailMerging
- assembly Wordize
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)
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 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
- enum SaveFormat
- class MailMergeOptions
- class MailMerger
- namespace Wordize.MailMerging
- assembly Wordize
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)
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 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
- enum SaveFormat
- class MailMergeOptions
- class MailMerger
- namespace Wordize.MailMerging
- assembly Wordize