Class MailMerger
Namespace: Aspose.Words.LowCode
Assembly: Aspose.Words.dll (25.12.0)
Provides methods intended to fill template with data using simple mail merge and mail merge with regions operations.
public class MailMerger : ProcessorInheritance
object ← Processor ← MailMerger
Inherited Members
Processor.mResultDocument , Processor.From(string) , Processor.From(string, LoadOptions) , Processor.From(Stream) , Processor.From(Stream, LoadOptions) , Processor.To(string) , Processor.To(string, SaveOptions) , Processor.To(string, SaveFormat) , Processor.To(Stream, SaveOptions) , Processor.To(Stream, SaveFormat) , Processor.To(List<Stream>, SaveOptions) , Processor.To(List<Stream>, SaveFormat) , Processor.Execute() , Processor.Execute(CancellationToken) , Processor.ExecuteCore() , Processor.CheckArgumentsSet() , Processor.GetPartFileName(string, int, SaveFormat) , object.GetType() , object.MemberwiseClone() , object.ToString() , object.Equals(object?) , object.Equals(object?, object?) , object.ReferenceEquals(object?, object?) , object.GetHashCode()
Methods
Create(MailMergerContext)
Creates new instance of the mail merger processor.
public static MailMerger Create(MailMergerContext context)Parameters
context MailMergerContext
Returns
Examples
Shows how to do mail merge operation for a single record using context.
// There is a several ways to do mail merge operation:
string doc = MyDir + "Mail merge.doc";
string[] fieldNames = new string[] { "FirstName", "Location", "SpecialCharsInName()" };
string[] fieldValues = new string[] { "James Bond", "London", "Classified" };
MailMergerContext mailMergerContext = new MailMergerContext();
mailMergerContext.SetSimpleDataSource(fieldNames, fieldValues);
mailMergerContext.MailMergeOptions.TrimWhitespaces = true;
MailMerger.Create(mailMergerContext)
.From(doc)
.To(ArtifactsDir + "LowCode.MailMergeContext.docx")
.Execute();Shows how to do mail merge operation from a DataRow using context.
// There is a several ways to do mail merge operation from a DataRow:
string doc = MyDir + "Mail merge.doc";
DataTable dataTable = new DataTable();
dataTable.Columns.Add("FirstName");
dataTable.Columns.Add("Location");
dataTable.Columns.Add("SpecialCharsInName()");
DataRow dataRow = dataTable.Rows.Add(new string[] { "James Bond", "London", "Classified" });
MailMergerContext mailMergerContext = new MailMergerContext();
mailMergerContext.SetSimpleDataSource(dataRow);
mailMergerContext.MailMergeOptions.TrimWhitespaces = true;
MailMerger.Create(mailMergerContext)
.From(doc)
.To(ArtifactsDir + "LowCode.MailMergeContextDataRow.docx")
.Execute();Shows how to do mail merge operation from a DataTable using context.
// There is a several ways to do mail merge operation from a DataTable:
string doc = MyDir + "Mail merge.doc";
DataTable dataTable = new DataTable();
dataTable.Columns.Add("FirstName");
dataTable.Columns.Add("Location");
dataTable.Columns.Add("SpecialCharsInName()");
DataRow dataRow = dataTable.Rows.Add(new string[] { "James Bond", "London", "Classified" });
MailMergerContext mailMergerContext = new MailMergerContext();
mailMergerContext.SetSimpleDataSource(dataTable);
mailMergerContext.MailMergeOptions.TrimWhitespaces = true;
MailMerger.Create(mailMergerContext)
.From(doc)
.To(ArtifactsDir + "LowCode.MailMergeContextDataTable.docx")
.Execute();Shows how to do mail merge with regions operation from a DataTable using context.
// There is a several ways to do mail merge with regions operation from a DataTable:
string doc = MyDir + "Mail merge with regions.docx";
DataTable dataTable = new DataTable("MyTable");
dataTable.Columns.Add("FirstName");
dataTable.Columns.Add("LastName");
dataTable.Rows.Add(new object[] { "John", "Doe" });
dataTable.Rows.Add(new object[] { "", "" });
dataTable.Rows.Add(new object[] { "Jane", "Doe" });
MailMergerContext mailMergerContext = new MailMergerContext();
mailMergerContext.SetRegionsDataSource(dataTable);
mailMergerContext.MailMergeOptions.TrimWhitespaces = true;
MailMerger.Create(mailMergerContext)
.From(doc)
.To(ArtifactsDir + "LowCode.MailMergeContextWithRegionsDataTable.docx")
.Execute();Shows how to do mail merge operation for a single record from the stream using context.
// There is a several ways to do mail merge operation using documents from the stream:
string[] fieldNames = new string[] { "FirstName", "Location", "SpecialCharsInName()" };
string[] fieldValues = new string[] { "James Bond", "London", "Classified" };
using (FileStream streamIn = new FileStream(MyDir + "Mail merge.doc", FileMode.Open, FileAccess.Read))
{
MailMergerContext mailMergerContext = new MailMergerContext();
mailMergerContext.SetSimpleDataSource(fieldNames, fieldValues);
mailMergerContext.MailMergeOptions.TrimWhitespaces = true;
using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.MailMergeContextStream.docx", FileMode.Create, FileAccess.ReadWrite))
MailMerger.Create(mailMergerContext)
.From(streamIn)
.To(streamOut, SaveFormat.Docx)
.Execute();
}Shows how to do mail merge operation from a DataRow using documents from the stream using context.
// There is a several ways to do mail merge operation from a DataRow using documents from the stream:
DataTable dataTable = new DataTable();
dataTable.Columns.Add("FirstName");
dataTable.Columns.Add("Location");
dataTable.Columns.Add("SpecialCharsInName()");
DataRow dataRow = dataTable.Rows.Add(new string[] { "James Bond", "London", "Classified" });
using (FileStream streamIn = new FileStream(MyDir + "Mail merge.doc", FileMode.Open, FileAccess.Read))
{
MailMergerContext mailMergerContext = new MailMergerContext();
mailMergerContext.SetSimpleDataSource(dataRow);
mailMergerContext.MailMergeOptions.TrimWhitespaces = true;
using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.MailMergeContextStreamDataRow.docx", FileMode.Create, FileAccess.ReadWrite))
MailMerger.Create(mailMergerContext)
.From(streamIn)
.To(streamOut, SaveFormat.Docx)
.Execute();
}Shows how to do mail merge operation from a DataTable using documents from the stream using context.
// There is a several ways to do mail merge operation from a DataTable using documents from the stream:
DataTable dataTable = new DataTable();
dataTable.Columns.Add("FirstName");
dataTable.Columns.Add("Location");
dataTable.Columns.Add("SpecialCharsInName()");
DataRow dataRow = dataTable.Rows.Add(new string[] { "James Bond", "London", "Classified" });
using (FileStream streamIn = new FileStream(MyDir + "Mail merge.doc", FileMode.Open, FileAccess.Read))
{
MailMergerContext mailMergerContext = new MailMergerContext();
mailMergerContext.SetSimpleDataSource(dataTable);
mailMergerContext.MailMergeOptions.TrimWhitespaces = true;
using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.MailMergeContextStreamDataTable.docx", FileMode.Create, FileAccess.ReadWrite))
MailMerger.Create(mailMergerContext)
.From(streamIn)
.To(streamOut, SaveFormat.Docx)
.Execute();
}Shows how to do mail merge with regions operation from a DataTable using documents from the stream using context.
// There is a several ways to do mail merge with regions operation from a DataTable using documents from the stream:
DataTable dataTable = new DataTable("MyTable");
dataTable.Columns.Add("FirstName");
dataTable.Columns.Add("LastName");
dataTable.Rows.Add(new object[] { "John", "Doe" });
dataTable.Rows.Add(new object[] { "", "" });
dataTable.Rows.Add(new object[] { "Jane", "Doe" });
using (FileStream streamIn = new FileStream(MyDir + "Mail merge.doc", FileMode.Open, FileAccess.Read))
{
MailMergerContext mailMergerContext = new MailMergerContext();
mailMergerContext.SetRegionsDataSource(dataTable);
mailMergerContext.MailMergeOptions.TrimWhitespaces = true;
using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.MailMergeContextStreamWithRegionsDataTable.docx", FileMode.Create, FileAccess.ReadWrite))
MailMerger.Create(mailMergerContext)
.From(streamIn)
.To(streamOut, SaveFormat.Docx)
.Execute();
}Shows how to do mail merge with regions operation from a DataSet using context.
// There is a several ways to do mail merge with regions operation from a DataSet:
string doc = MyDir + "Mail merge with regions data set.docx";
DataTable tableCustomers = new DataTable("Customers");
tableCustomers.Columns.Add("CustomerID");
tableCustomers.Columns.Add("CustomerName");
tableCustomers.Rows.Add(new object[] { 1, "John Doe" });
tableCustomers.Rows.Add(new object[] { 2, "Jane Doe" });
DataTable tableOrders = new DataTable("Orders");
tableOrders.Columns.Add("CustomerID");
tableOrders.Columns.Add("ItemName");
tableOrders.Columns.Add("Quantity");
tableOrders.Rows.Add(new object[] { 1, "Hawaiian", 2 });
tableOrders.Rows.Add(new object[] { 2, "Pepperoni", 1 });
tableOrders.Rows.Add(new object[] { 2, "Chicago", 1 });
DataSet dataSet = new DataSet();
dataSet.Tables.Add(tableCustomers);
dataSet.Tables.Add(tableOrders);
dataSet.Relations.Add(tableCustomers.Columns["CustomerID"], tableOrders.Columns["CustomerID"]);
MailMergerContext mailMergerContext = new MailMergerContext();
mailMergerContext.SetRegionsDataSource(dataSet);
mailMergerContext.MailMergeOptions.TrimWhitespaces = true;
MailMerger.Create(mailMergerContext)
.From(doc)
.To(ArtifactsDir + "LowCode.MailMergeContextWithRegionsDataTable.docx")
.Execute();Shows how to do mail merge with regions operation from a DataSet using documents from the stream using context.
// There is a several ways to do mail merge with regions operation from a DataSet using documents from the stream:
DataTable tableCustomers = new DataTable("Customers");
tableCustomers.Columns.Add("CustomerID");
tableCustomers.Columns.Add("CustomerName");
tableCustomers.Rows.Add(new object[] { 1, "John Doe" });
tableCustomers.Rows.Add(new object[] { 2, "Jane Doe" });
DataTable tableOrders = new DataTable("Orders");
tableOrders.Columns.Add("CustomerID");
tableOrders.Columns.Add("ItemName");
tableOrders.Columns.Add("Quantity");
tableOrders.Rows.Add(new object[] { 1, "Hawaiian", 2 });
tableOrders.Rows.Add(new object[] { 2, "Pepperoni", 1 });
tableOrders.Rows.Add(new object[] { 2, "Chicago", 1 });
DataSet dataSet = new DataSet();
dataSet.Tables.Add(tableCustomers);
dataSet.Tables.Add(tableOrders);
dataSet.Relations.Add(tableCustomers.Columns["CustomerID"], tableOrders.Columns["CustomerID"]);
using (FileStream streamIn = new FileStream(MyDir + "Mail merge.doc", FileMode.Open, FileAccess.Read))
{
MailMergerContext mailMergerContext = new MailMergerContext();
mailMergerContext.SetRegionsDataSource(dataSet);
mailMergerContext.MailMergeOptions.TrimWhitespaces = true;
using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.MailMergeContextStreamWithRegionsDataSet.docx", FileMode.Create, FileAccess.ReadWrite))
MailMerger.Create(mailMergerContext)
.From(streamIn)
.To(streamOut, SaveFormat.Docx)
.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)Parameters
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.
Examples
Shows how to do mail merge operation for a single record.
// There is a several ways to do mail merge operation:
string doc = MyDir + "Mail merge.doc";
string[] fieldNames = new string[] { "FirstName", "Location", "SpecialCharsInName()" };
string[] fieldValues = new string[] { "James Bond", "London", "Classified" };
MailMerger.Execute(doc, ArtifactsDir + "LowCode.MailMerge.1.docx", fieldNames, fieldValues);
MailMerger.Execute(doc, ArtifactsDir + "LowCode.MailMerge.2.docx", SaveFormat.Docx, fieldNames, fieldValues);
MailMergeOptions mailMergeOptions = new MailMergeOptions();
mailMergeOptions.TrimWhitespaces = true;
MailMerger.Execute(doc, ArtifactsDir + "LowCode.MailMerge.3.docx", SaveFormat.Docx, fieldNames, fieldValues, mailMergeOptions);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.
Execute(string, string, SaveFormat, string[], object[])
Performs a mail merge operation for a single record.
public static void Execute(string inputFileName, string outputFileName, SaveFormat saveFormat, string[] fieldNames, object[] fieldValues)Parameters
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.
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.
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)Parameters
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.
Examples
Shows how to do mail merge operation for a single record.
// There is a several ways to do mail merge operation:
string doc = MyDir + "Mail merge.doc";
string[] fieldNames = new string[] { "FirstName", "Location", "SpecialCharsInName()" };
string[] fieldValues = new string[] { "James Bond", "London", "Classified" };
MailMerger.Execute(doc, ArtifactsDir + "LowCode.MailMerge.1.docx", fieldNames, fieldValues);
MailMerger.Execute(doc, ArtifactsDir + "LowCode.MailMerge.2.docx", SaveFormat.Docx, fieldNames, fieldValues);
MailMergeOptions mailMergeOptions = new MailMergeOptions();
mailMergeOptions.TrimWhitespaces = true;
MailMerger.Execute(doc, ArtifactsDir + "LowCode.MailMerge.3.docx", SaveFormat.Docx, fieldNames, fieldValues, mailMergeOptions);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.
Execute(string, string, SaveOptions, string[], object[])
Performs a mail merge operation for a single record.
public static void Execute(string inputFileName, string outputFileName, SaveOptions saveOptions, string[] fieldNames, object[] fieldValues)Parameters
inputFileName string
The input file name.
outputFileName string
The output file name.
saveOptions SaveOptions
The output’s save options.
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.
Execute(string, string, SaveOptions, string[], object[], MailMergeOptions)
Performs a mail merge operation for a single record.
public static void Execute(string inputFileName, string outputFileName, SaveOptions saveOptions, string[] fieldNames, object[] fieldValues, MailMergeOptions mailMergeOptions)Parameters
inputFileName string
The input file name.
outputFileName string
The output file name.
saveOptions SaveOptions
The output’s save options.
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.
Execute(Stream, Stream, SaveFormat, string[], object[])
Performs a mail merge operation for a single record.
public static void Execute(Stream inputStream, Stream outputStream, SaveFormat saveFormat, string[] fieldNames, object[] fieldValues)Parameters
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.
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.
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)Parameters
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.
Examples
Shows how to do mail merge operation for a single record from the stream.
// There is a several ways to do mail merge operation using documents from the stream:
string[] fieldNames = new string[] { "FirstName", "Location", "SpecialCharsInName()" };
string[] fieldValues = new string[] { "James Bond", "London", "Classified" };
using (FileStream streamIn = new FileStream(MyDir + "Mail merge.doc", FileMode.Open, FileAccess.Read))
{
using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.MailMergeStream.1.docx", FileMode.Create, FileAccess.ReadWrite))
MailMerger.Execute(streamIn, streamOut, SaveFormat.Docx, fieldNames, fieldValues);
using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.MailMergeStream.2.docx", FileMode.Create, FileAccess.ReadWrite))
{
MailMergeOptions mailMergeOptions = new MailMergeOptions();
mailMergeOptions.TrimWhitespaces = true;
MailMerger.Execute(streamIn, streamOut, SaveFormat.Docx, fieldNames, fieldValues, mailMergeOptions);
}
}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.
Execute(Stream, Stream, SaveOptions, string[], object[])
Performs a mail merge operation for a single record.
public static void Execute(Stream inputStream, Stream outputStream, SaveOptions saveOptions, string[] fieldNames, object[] fieldValues)Parameters
inputStream Stream
The input file stream.
outputStream Stream
The output file stream.
saveOptions SaveOptions
The output’s save options.
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), 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.
Execute(Stream, Stream, SaveOptions, string[], object[], MailMergeOptions)
Performs a mail merge operation for a single record.
public static void Execute(Stream inputStream, Stream outputStream, SaveOptions saveOptions, string[] fieldNames, object[] fieldValues, MailMergeOptions mailMergeOptions)Parameters
inputStream Stream
The input file stream.
outputStream Stream
The output file stream.
saveOptions SaveOptions
The output’s save options.
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.
Execute(string, string, DataRow)
Performs mail merge from a DataRow into the document.
public static void Execute(string inputFileName, string outputFileName, DataRow dataRow)Parameters
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.
Examples
Shows how to do mail merge operation from a DataRow.
// There is a several ways to do mail merge operation from a DataRow:
string doc = MyDir + "Mail merge.doc";
DataTable dataTable = new DataTable();
dataTable.Columns.Add("FirstName");
dataTable.Columns.Add("Location");
dataTable.Columns.Add("SpecialCharsInName()");
DataRow dataRow = dataTable.Rows.Add(new string[] { "James Bond", "London", "Classified" });
MailMerger.Execute(doc, ArtifactsDir + "LowCode.MailMergeDataRow.1.docx", dataRow);
MailMerger.Execute(doc, ArtifactsDir + "LowCode.MailMergeDataRow.2.docx", SaveFormat.Docx, dataRow);
MailMerger.Execute(doc, ArtifactsDir + "LowCode.MailMergeDataRow.3.docx", SaveFormat.Docx, dataRow, new MailMergeOptions() { TrimWhitespaces = true });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.
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)Parameters
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.
Examples
Shows how to do mail merge operation from a DataRow.
// There is a several ways to do mail merge operation from a DataRow:
string doc = MyDir + "Mail merge.doc";
DataTable dataTable = new DataTable();
dataTable.Columns.Add("FirstName");
dataTable.Columns.Add("Location");
dataTable.Columns.Add("SpecialCharsInName()");
DataRow dataRow = dataTable.Rows.Add(new string[] { "James Bond", "London", "Classified" });
MailMerger.Execute(doc, ArtifactsDir + "LowCode.MailMergeDataRow.1.docx", dataRow);
MailMerger.Execute(doc, ArtifactsDir + "LowCode.MailMergeDataRow.2.docx", SaveFormat.Docx, dataRow);
MailMerger.Execute(doc, ArtifactsDir + "LowCode.MailMergeDataRow.3.docx", SaveFormat.Docx, dataRow, new MailMergeOptions() { TrimWhitespaces = true });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.
Execute(string, string, SaveOptions, DataRow, MailMergeOptions)
Performs mail merge from a DataRow into the document.
public static void Execute(string inputFileName, string outputFileName, SaveOptions saveOptions, DataRow dataRow, MailMergeOptions mailMergeOptions = null)Parameters
inputFileName string
The input file name.
outputFileName string
The output file name.
saveOptions SaveOptions
The output’s save options.
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.
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)Parameters
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.
Examples
Shows how to do mail merge operation from a DataRow using documents from the stream.
// There is a several ways to do mail merge operation from a DataRow using documents from the stream:
DataTable dataTable = new DataTable();
dataTable.Columns.Add("FirstName");
dataTable.Columns.Add("Location");
dataTable.Columns.Add("SpecialCharsInName()");
DataRow dataRow = dataTable.Rows.Add(new string[] { "James Bond", "London", "Classified" });
using (FileStream streamIn = new FileStream(MyDir + "Mail merge.doc", FileMode.Open, FileAccess.Read))
{
using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.MailMergeStreamDataRow.1.docx", FileMode.Create, FileAccess.ReadWrite))
MailMerger.Execute(streamIn, streamOut, SaveFormat.Docx, dataRow);
using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.MailMergeStreamDataRow.2.docx", FileMode.Create, FileAccess.ReadWrite))
MailMerger.Execute(streamIn, streamOut, SaveFormat.Docx, dataRow, new MailMergeOptions() { TrimWhitespaces = true });
}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.
Execute(Stream, Stream, SaveOptions, DataRow, MailMergeOptions)
Performs a mail merge operation for a single record.
public static void Execute(Stream inputStream, Stream outputStream, SaveOptions saveOptions, DataRow dataRow, MailMergeOptions mailMergeOptions = null)Parameters
inputStream Stream
The input file stream.
outputStream Stream
The output file stream.
saveOptions SaveOptions
The output’s save options.
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.
Execute(string, string, DataTable)
Performs mail merge from a DataTable into the document.
public static void Execute(string inputFileName, string outputFileName, DataTable dataTable)Parameters
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.
Examples
Shows how to do mail merge operation from a DataTable.
// There is a several ways to do mail merge operation from a DataTable:
string doc = MyDir + "Mail merge.doc";
DataTable dataTable = new DataTable();
dataTable.Columns.Add("FirstName");
dataTable.Columns.Add("Location");
dataTable.Columns.Add("SpecialCharsInName()");
DataRow dataRow = dataTable.Rows.Add(new string[] { "James Bond", "London", "Classified" });
MailMerger.Execute(doc, ArtifactsDir + "LowCode.MailMergeDataTable.1.docx", dataTable);
MailMerger.Execute(doc, ArtifactsDir + "LowCode.MailMergeDataTable.2.docx", SaveFormat.Docx, dataTable);
MailMerger.Execute(doc, ArtifactsDir + "LowCode.MailMergeDataTable.3.docx", SaveFormat.Docx, dataTable, new MailMergeOptions() { TrimWhitespaces = true });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.
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)Parameters
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.
Examples
Shows how to do mail merge operation from a DataTable.
// There is a several ways to do mail merge operation from a DataTable:
string doc = MyDir + "Mail merge.doc";
DataTable dataTable = new DataTable();
dataTable.Columns.Add("FirstName");
dataTable.Columns.Add("Location");
dataTable.Columns.Add("SpecialCharsInName()");
DataRow dataRow = dataTable.Rows.Add(new string[] { "James Bond", "London", "Classified" });
MailMerger.Execute(doc, ArtifactsDir + "LowCode.MailMergeDataTable.1.docx", dataTable);
MailMerger.Execute(doc, ArtifactsDir + "LowCode.MailMergeDataTable.2.docx", SaveFormat.Docx, dataTable);
MailMerger.Execute(doc, ArtifactsDir + "LowCode.MailMergeDataTable.3.docx", SaveFormat.Docx, dataTable, new MailMergeOptions() { TrimWhitespaces = true });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.
Execute(string, string, SaveOptions, DataTable, MailMergeOptions)
Performs mail merge from a DataRow into the document.
public static void Execute(string inputFileName, string outputFileName, SaveOptions saveOptions, DataTable dataTable, MailMergeOptions mailMergeOptions = null)Parameters
inputFileName string
The input file name.
outputFileName string
The output file name.
saveOptions SaveOptions
The output’s save options.
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.
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)Parameters
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.
Examples
Shows how to do mail merge operation from a DataTable using documents from the stream.
// There is a several ways to do mail merge operation from a DataTable using documents from the stream:
DataTable dataTable = new DataTable();
dataTable.Columns.Add("FirstName");
dataTable.Columns.Add("Location");
dataTable.Columns.Add("SpecialCharsInName()");
DataRow dataRow = dataTable.Rows.Add(new string[] { "James Bond", "London", "Classified" });
using (FileStream streamIn = new FileStream(MyDir + "Mail merge.doc", FileMode.Open, FileAccess.Read))
{
using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.MailMergeDataTable.1.docx", FileMode.Create, FileAccess.ReadWrite))
MailMerger.Execute(streamIn, streamOut, SaveFormat.Docx, dataTable);
using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.MailMergeDataTable.2.docx", FileMode.Create, FileAccess.ReadWrite))
MailMerger.Execute(streamIn, streamOut, SaveFormat.Docx, dataTable, new MailMergeOptions() { TrimWhitespaces = true });
}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.
Execute(Stream, Stream, SaveOptions, DataTable, MailMergeOptions)
Performs a mail merge operation for a single record.
public static void Execute(Stream inputStream, Stream outputStream, SaveOptions saveOptions, DataTable dataTable, MailMergeOptions mailMergeOptions = null)Parameters
inputStream Stream
The input file stream.
outputStream Stream
The output file stream.
saveOptions SaveOptions
The output’s save options.
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.
ExecuteCore()
protected override void ExecuteCore()ExecuteToImages(string, ImageSaveOptions, string[], object[])
Performs a mail merge operation for a single record and renders the result to images.
public static Stream[] ExecuteToImages(string inputFileName, ImageSaveOptions saveOptions, string[] fieldNames, object[] fieldValues)Parameters
inputFileName string
The input file name.
saveOptions ImageSaveOptions
The output’s save options.
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.
Returns
Stream []
ExecuteToImages(string, ImageSaveOptions, string[], object[], MailMergeOptions)
Performs a mail merge operation for a single record and renders the result to images.
public static Stream[] ExecuteToImages(string inputFileName, ImageSaveOptions saveOptions, string[] fieldNames, object[] fieldValues, MailMergeOptions mailMergeOptions)Parameters
inputFileName string
The input file name.
saveOptions ImageSaveOptions
The output’s save options.
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.
Returns
Stream []
Examples
Shows how to do mail merge operation for a single record and save result to images.
// There is a several ways to do mail merge operation:
string doc = MyDir + "Mail merge.doc";
string[] fieldNames = new string[] { "FirstName", "Location", "SpecialCharsInName()" };
string[] fieldValues = new string[] { "James Bond", "London", "Classified" };
Stream[] images = MailMerger.ExecuteToImages(doc, new ImageSaveOptions(SaveFormat.Png), fieldNames, fieldValues);
MailMergeOptions mailMergeOptions = new MailMergeOptions();
mailMergeOptions.TrimWhitespaces = true;
images = MailMerger.ExecuteToImages(doc, new ImageSaveOptions(SaveFormat.Png), fieldNames, fieldValues, mailMergeOptions);ExecuteToImages(Stream, ImageSaveOptions, string[], object[])
Performs a mail merge operation for a single record and renders the result to images.
public static Stream[] ExecuteToImages(Stream inputStream, ImageSaveOptions saveOptions, string[] fieldNames, object[] fieldValues)Parameters
inputStream Stream
The input file stream.
saveOptions ImageSaveOptions
The output’s save options.
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.
Returns
Stream []
ExecuteToImages(Stream, ImageSaveOptions, string[], object[], MailMergeOptions)
Performs a mail merge operation for a single record and renders the result to images.
public static Stream[] ExecuteToImages(Stream inputStream, ImageSaveOptions saveOptions, string[] fieldNames, object[] fieldValues, MailMergeOptions mailMergeOptions)Parameters
inputStream Stream
The input file stream.
saveOptions ImageSaveOptions
The output’s save options.
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.
Returns
Stream []
Examples
Shows how to do mail merge operation for a single record from the stream and save result to images.
// There is a several ways to do mail merge operation using documents from the stream:
string[] fieldNames = new string[] { "FirstName", "Location", "SpecialCharsInName()" };
string[] fieldValues = new string[] { "James Bond", "London", "Classified" };
using (FileStream streamIn = new FileStream(MyDir + "Mail merge.doc", FileMode.Open, FileAccess.Read))
{
Stream[] images = MailMerger.ExecuteToImages(streamIn, new ImageSaveOptions(SaveFormat.Png), fieldNames, fieldValues);
MailMergeOptions mailMergeOptions = new MailMergeOptions();
mailMergeOptions.TrimWhitespaces = true;
images = MailMerger.ExecuteToImages(streamIn, new ImageSaveOptions(SaveFormat.Png), fieldNames, fieldValues, mailMergeOptions);
}ExecuteToImages(string, ImageSaveOptions, DataRow, MailMergeOptions)
Performs mail merge from a DataRow into the document and renders the result to images.
public static Stream[] ExecuteToImages(string inputFileName, ImageSaveOptions saveOptions, DataRow dataRow, MailMergeOptions mailMergeOptions = null)Parameters
inputFileName string
The input file name.
saveOptions ImageSaveOptions
The output’s save options.
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.
Returns
Stream []
Examples
Shows how to do mail merge operation from a DataRow and save result to images.
// There is a several ways to do mail merge operation from a DataRow:
string doc = MyDir + "Mail merge.doc";
DataTable dataTable = new DataTable();
dataTable.Columns.Add("FirstName");
dataTable.Columns.Add("Location");
dataTable.Columns.Add("SpecialCharsInName()");
DataRow dataRow = dataTable.Rows.Add(new string[] { "James Bond", "London", "Classified" });
Stream[] images = MailMerger.ExecuteToImages(doc, new ImageSaveOptions(SaveFormat.Png), dataRow);
images = MailMerger.ExecuteToImages(doc, new ImageSaveOptions(SaveFormat.Png), dataRow, new MailMergeOptions() { TrimWhitespaces = true });ExecuteToImages(Stream, ImageSaveOptions, DataRow, MailMergeOptions)
Performs mail merge from a DataRow into the document and renders the result to images.
public static Stream[] ExecuteToImages(Stream inputStream, ImageSaveOptions saveOptions, DataRow dataRow, MailMergeOptions mailMergeOptions = null)Parameters
inputStream Stream
The input file stream.
saveOptions ImageSaveOptions
The output’s save options.
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.
Returns
Stream []
Examples
Shows how to do mail merge operation from a DataRow using documents from the stream and save result to images.
// There is a several ways to do mail merge operation from a DataRow using documents from the stream:
DataTable dataTable = new DataTable();
dataTable.Columns.Add("FirstName");
dataTable.Columns.Add("Location");
dataTable.Columns.Add("SpecialCharsInName()");
DataRow dataRow = dataTable.Rows.Add(new string[] { "James Bond", "London", "Classified" });
using (FileStream streamIn = new FileStream(MyDir + "Mail merge.doc", FileMode.Open, FileAccess.Read))
{
Stream[] images = MailMerger.ExecuteToImages(streamIn, new ImageSaveOptions(SaveFormat.Png), dataRow);
images = MailMerger.ExecuteToImages(streamIn, new ImageSaveOptions(SaveFormat.Png), dataRow, new MailMergeOptions() { TrimWhitespaces = true });
}ExecuteToImages(string, ImageSaveOptions, DataTable, MailMergeOptions)
Performs mail merge from a DataRow into the document and renders the result to images.
public static Stream[] ExecuteToImages(string inputFileName, ImageSaveOptions saveOptions, DataTable dataTable, MailMergeOptions mailMergeOptions = null)Parameters
inputFileName string
The input file name.
saveOptions ImageSaveOptions
The output’s save options.
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.
Returns
Stream []
Examples
Shows how to do mail merge operation from a DataTable and save result to images.
// There is a several ways to do mail merge operation from a DataTable:
string doc = MyDir + "Mail merge.doc";
DataTable dataTable = new DataTable();
dataTable.Columns.Add("FirstName");
dataTable.Columns.Add("Location");
dataTable.Columns.Add("SpecialCharsInName()");
DataRow dataRow = dataTable.Rows.Add(new string[] { "James Bond", "London", "Classified" });
Stream[] images = MailMerger.ExecuteToImages(doc, new ImageSaveOptions(SaveFormat.Png), dataTable);
images = MailMerger.ExecuteToImages(doc, new ImageSaveOptions(SaveFormat.Png), dataTable, new MailMergeOptions() { TrimWhitespaces = true });ExecuteToImages(Stream, ImageSaveOptions, DataTable, MailMergeOptions)
Performs mail merge from a DataRow into the document and renders the result to images.
public static Stream[] ExecuteToImages(Stream inputStream, ImageSaveOptions saveOptions, DataTable dataTable, MailMergeOptions mailMergeOptions = null)Parameters
inputStream Stream
The input file stream.
saveOptions ImageSaveOptions
The output’s save options.
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.
Returns
Stream []
Examples
Shows how to do mail merge operation from a DataTable using documents from the stream and save to images.
// There is a several ways to do mail merge operation from a DataTable using documents from the stream and save result to images:
DataTable dataTable = new DataTable();
dataTable.Columns.Add("FirstName");
dataTable.Columns.Add("Location");
dataTable.Columns.Add("SpecialCharsInName()");
DataRow dataRow = dataTable.Rows.Add(new string[] { "James Bond", "London", "Classified" });
using (FileStream streamIn = new FileStream(MyDir + "Mail merge.doc", FileMode.Open, FileAccess.Read))
{
Stream[] images = MailMerger.ExecuteToImages(streamIn, new ImageSaveOptions(SaveFormat.Png), dataTable);
images = MailMerger.ExecuteToImages(streamIn, new ImageSaveOptions(SaveFormat.Png), dataTable, new MailMergeOptions() { TrimWhitespaces = true });
}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)Parameters
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.
Examples
Shows how to do mail merge with regions operation from a DataTable.
// There is a several ways to do mail merge with regions operation from a DataTable:
string doc = MyDir + "Mail merge with regions.docx";
DataTable dataTable = new DataTable("MyTable");
dataTable.Columns.Add("FirstName");
dataTable.Columns.Add("LastName");
dataTable.Rows.Add(new object[] { "John", "Doe" });
dataTable.Rows.Add(new object[] { "", "" });
dataTable.Rows.Add(new object[] { "Jane", "Doe" });
MailMerger.ExecuteWithRegions(doc, ArtifactsDir + "LowCode.MailMergeWithRegionsDataTable.1.docx", dataTable);
MailMerger.ExecuteWithRegions(doc, ArtifactsDir + "LowCode.MailMergeWithRegionsDataTable.2.docx", SaveFormat.Docx, dataTable);
MailMerger.ExecuteWithRegions(doc, ArtifactsDir + "LowCode.MailMergeWithRegionsDataTable.3.docx", SaveFormat.Docx, dataTable, new MailMergeOptions() { TrimWhitespaces = true });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.
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)Parameters
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.
Examples
Shows how to do mail merge with regions operation from a DataTable.
// There is a several ways to do mail merge with regions operation from a DataTable:
string doc = MyDir + "Mail merge with regions.docx";
DataTable dataTable = new DataTable("MyTable");
dataTable.Columns.Add("FirstName");
dataTable.Columns.Add("LastName");
dataTable.Rows.Add(new object[] { "John", "Doe" });
dataTable.Rows.Add(new object[] { "", "" });
dataTable.Rows.Add(new object[] { "Jane", "Doe" });
MailMerger.ExecuteWithRegions(doc, ArtifactsDir + "LowCode.MailMergeWithRegionsDataTable.1.docx", dataTable);
MailMerger.ExecuteWithRegions(doc, ArtifactsDir + "LowCode.MailMergeWithRegionsDataTable.2.docx", SaveFormat.Docx, dataTable);
MailMerger.ExecuteWithRegions(doc, ArtifactsDir + "LowCode.MailMergeWithRegionsDataTable.3.docx", SaveFormat.Docx, dataTable, new MailMergeOptions() { TrimWhitespaces = true });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.
ExecuteWithRegions(string, string, SaveOptions, DataTable, MailMergeOptions)
Performs mail merge from a DataTable into the document with mail merge regions.
public static void ExecuteWithRegions(string inputFileName, string outputFileName, SaveOptions saveOptions, DataTable dataTable, MailMergeOptions mailMergeOptions = null)Parameters
inputFileName string
The input file name.
outputFileName string
The output file name.
saveOptions SaveOptions
The output’s save options.
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.
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)Parameters
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.
Examples
Shows how to do mail merge with regions operation from a DataTable using documents from the stream.
// There is a several ways to do mail merge with regions operation from a DataTable using documents from the stream:
DataTable dataTable = new DataTable("MyTable");
dataTable.Columns.Add("FirstName");
dataTable.Columns.Add("LastName");
dataTable.Rows.Add(new object[] { "John", "Doe" });
dataTable.Rows.Add(new object[] { "", "" });
dataTable.Rows.Add(new object[] { "Jane", "Doe" });
using (FileStream streamIn = new FileStream(MyDir + "Mail merge.doc", FileMode.Open, FileAccess.Read))
{
using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.MailMergeStreamWithRegionsDataTable.1.docx", FileMode.Create, FileAccess.ReadWrite))
MailMerger.ExecuteWithRegions(streamIn, streamOut, SaveFormat.Docx, dataTable);
using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.MailMergeStreamWithRegionsDataTable.2.docx", FileMode.Create, FileAccess.ReadWrite))
MailMerger.ExecuteWithRegions(streamIn, streamOut, SaveFormat.Docx, dataTable, new MailMergeOptions() { TrimWhitespaces = true });
}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.
ExecuteWithRegions(Stream, Stream, SaveOptions, DataTable, MailMergeOptions)
Performs a mail merge operation for a single record.
public static void ExecuteWithRegions(Stream inputStream, Stream outputStream, SaveOptions saveOptions, DataTable dataTable, MailMergeOptions mailMergeOptions = null)Parameters
inputStream Stream
The input file stream.
outputStream Stream
The output file stream.
saveOptions SaveOptions
The output’s save options.
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.
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)Parameters
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.
Examples
Shows how to do mail merge with regions operation from a DataSet.
// There is a several ways to do mail merge with regions operation from a DataSet:
string doc = MyDir + "Mail merge with regions data set.docx";
DataTable tableCustomers = new DataTable("Customers");
tableCustomers.Columns.Add("CustomerID");
tableCustomers.Columns.Add("CustomerName");
tableCustomers.Rows.Add(new object[] { 1, "John Doe" });
tableCustomers.Rows.Add(new object[] { 2, "Jane Doe" });
DataTable tableOrders = new DataTable("Orders");
tableOrders.Columns.Add("CustomerID");
tableOrders.Columns.Add("ItemName");
tableOrders.Columns.Add("Quantity");
tableOrders.Rows.Add(new object[] { 1, "Hawaiian", 2 });
tableOrders.Rows.Add(new object[] { 2, "Pepperoni", 1 });
tableOrders.Rows.Add(new object[] { 2, "Chicago", 1 });
DataSet dataSet = new DataSet();
dataSet.Tables.Add(tableCustomers);
dataSet.Tables.Add(tableOrders);
dataSet.Relations.Add(tableCustomers.Columns["CustomerID"], tableOrders.Columns["CustomerID"]);
MailMerger.ExecuteWithRegions(doc, ArtifactsDir + "LowCode.MailMergeWithRegionsDataSet.1.docx", dataSet);
MailMerger.ExecuteWithRegions(doc, ArtifactsDir + "LowCode.MailMergeWithRegionsDataSet.2.docx", SaveFormat.Docx, dataSet);
MailMerger.ExecuteWithRegions(doc, ArtifactsDir + "LowCode.MailMergeWithRegionsDataSet.3.docx", SaveFormat.Docx, dataSet, new MailMergeOptions() { TrimWhitespaces = true });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.
ExecuteWithRegions(string, string, SaveFormat, DataSet, MailMergeOptions)
Performs mail merge from a DataSet into the document with mail merge regions.
public static void ExecuteWithRegions(string inputFileName, string outputFileName, SaveFormat saveFormat, DataSet dataSet, MailMergeOptions mailMergeOptions = null)Parameters
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.
Examples
Shows how to do mail merge with regions operation from a DataSet.
// There is a several ways to do mail merge with regions operation from a DataSet:
string doc = MyDir + "Mail merge with regions data set.docx";
DataTable tableCustomers = new DataTable("Customers");
tableCustomers.Columns.Add("CustomerID");
tableCustomers.Columns.Add("CustomerName");
tableCustomers.Rows.Add(new object[] { 1, "John Doe" });
tableCustomers.Rows.Add(new object[] { 2, "Jane Doe" });
DataTable tableOrders = new DataTable("Orders");
tableOrders.Columns.Add("CustomerID");
tableOrders.Columns.Add("ItemName");
tableOrders.Columns.Add("Quantity");
tableOrders.Rows.Add(new object[] { 1, "Hawaiian", 2 });
tableOrders.Rows.Add(new object[] { 2, "Pepperoni", 1 });
tableOrders.Rows.Add(new object[] { 2, "Chicago", 1 });
DataSet dataSet = new DataSet();
dataSet.Tables.Add(tableCustomers);
dataSet.Tables.Add(tableOrders);
dataSet.Relations.Add(tableCustomers.Columns["CustomerID"], tableOrders.Columns["CustomerID"]);
MailMerger.ExecuteWithRegions(doc, ArtifactsDir + "LowCode.MailMergeWithRegionsDataSet.1.docx", dataSet);
MailMerger.ExecuteWithRegions(doc, ArtifactsDir + "LowCode.MailMergeWithRegionsDataSet.2.docx", SaveFormat.Docx, dataSet);
MailMerger.ExecuteWithRegions(doc, ArtifactsDir + "LowCode.MailMergeWithRegionsDataSet.3.docx", SaveFormat.Docx, dataSet, new MailMergeOptions() { TrimWhitespaces = true });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.
ExecuteWithRegions(string, string, SaveOptions, DataSet, MailMergeOptions)
Performs mail merge from a DataSet into the document with mail merge regions.
public static void ExecuteWithRegions(string inputFileName, string outputFileName, SaveOptions saveOptions, DataSet dataSet, MailMergeOptions mailMergeOptions = null)Parameters
inputFileName string
The input file name.
outputFileName string
The output file name.
saveOptions SaveOptions
The output’s save options.
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.
ExecuteWithRegions(Stream, Stream, SaveFormat, DataSet, MailMergeOptions)
Performs mail merge from a DataSet into the document with mail merge regions.
public static void ExecuteWithRegions(Stream inputStream, Stream outputStream, SaveFormat saveFormat, DataSet dataSet, MailMergeOptions mailMergeOptions = null)Parameters
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.
Examples
Shows how to do mail merge with regions operation from a DataSet using documents from the stream.
// There is a several ways to do mail merge with regions operation from a DataSet using documents from the stream:
DataTable tableCustomers = new DataTable("Customers");
tableCustomers.Columns.Add("CustomerID");
tableCustomers.Columns.Add("CustomerName");
tableCustomers.Rows.Add(new object[] { 1, "John Doe" });
tableCustomers.Rows.Add(new object[] { 2, "Jane Doe" });
DataTable tableOrders = new DataTable("Orders");
tableOrders.Columns.Add("CustomerID");
tableOrders.Columns.Add("ItemName");
tableOrders.Columns.Add("Quantity");
tableOrders.Rows.Add(new object[] { 1, "Hawaiian", 2 });
tableOrders.Rows.Add(new object[] { 2, "Pepperoni", 1 });
tableOrders.Rows.Add(new object[] { 2, "Chicago", 1 });
DataSet dataSet = new DataSet();
dataSet.Tables.Add(tableCustomers);
dataSet.Tables.Add(tableOrders);
dataSet.Relations.Add(tableCustomers.Columns["CustomerID"], tableOrders.Columns["CustomerID"]);
using (FileStream streamIn = new FileStream(MyDir + "Mail merge.doc", FileMode.Open, FileAccess.Read))
{
using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.MailMergeStreamWithRegionsDataTable.1.docx", FileMode.Create, FileAccess.ReadWrite))
MailMerger.ExecuteWithRegions(streamIn, streamOut, SaveFormat.Docx, dataSet);
using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.MailMergeStreamWithRegionsDataTable.2.docx", FileMode.Create, FileAccess.ReadWrite))
MailMerger.ExecuteWithRegions(streamIn, streamOut, SaveFormat.Docx, dataSet, new MailMergeOptions() { TrimWhitespaces = true });
}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.
ExecuteWithRegions(Stream, Stream, SaveOptions, DataSet, MailMergeOptions)
Performs mail merge from a DataSet into the document with mail merge regions.
public static void ExecuteWithRegions(Stream inputStream, Stream outputStream, SaveOptions saveOptions, DataSet dataSet, MailMergeOptions mailMergeOptions = null)Parameters
inputStream Stream
The input file stream.
outputStream Stream
The output file stream.
saveOptions SaveOptions
The output’s save options.
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.
ExecuteWithRegionsToImages(string, ImageSaveOptions, DataTable, MailMergeOptions)
Performs mail merge from a DataTable into the document with mail merge regions and renders the result to images.
public static Stream[] ExecuteWithRegionsToImages(string inputFileName, ImageSaveOptions saveOptions, DataTable dataTable, MailMergeOptions mailMergeOptions = null)Parameters
inputFileName string
The input file name.
saveOptions ImageSaveOptions
The output’s save options.
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.
Returns
Stream []
Examples
Shows how to do mail merge with regions operation from a DataTable and save result to images.
// There is a several ways to do mail merge with regions operation from a DataTable:
string doc = MyDir + "Mail merge with regions.docx";
DataTable dataTable = new DataTable("MyTable");
dataTable.Columns.Add("FirstName");
dataTable.Columns.Add("LastName");
dataTable.Rows.Add(new object[] { "John", "Doe" });
dataTable.Rows.Add(new object[] { "", "" });
dataTable.Rows.Add(new object[] { "Jane", "Doe" });
Stream[] images = MailMerger.ExecuteWithRegionsToImages(doc, new ImageSaveOptions(SaveFormat.Png), dataTable);
images = MailMerger.ExecuteWithRegionsToImages(doc, new ImageSaveOptions(SaveFormat.Png), dataTable, new MailMergeOptions() { TrimWhitespaces = true });ExecuteWithRegionsToImages(Stream, ImageSaveOptions, DataTable, MailMergeOptions)
Performs mail merge from a DataTable into the document with mail merge regions and renders the result to images.
public static Stream[] ExecuteWithRegionsToImages(Stream inputStream, ImageSaveOptions saveOptions, DataTable dataTable, MailMergeOptions mailMergeOptions = null)Parameters
inputStream Stream
The input file stream.
saveOptions ImageSaveOptions
The output’s save options.
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.
Returns
Stream []
Examples
Shows how to do mail merge with regions operation from a DataTable using documents from the stream and save result to images.
// There is a several ways to do mail merge with regions operation from a DataTable using documents from the stream:
DataTable dataTable = new DataTable("MyTable");
dataTable.Columns.Add("FirstName");
dataTable.Columns.Add("LastName");
dataTable.Rows.Add(new object[] { "John", "Doe" });
dataTable.Rows.Add(new object[] { "", "" });
dataTable.Rows.Add(new object[] { "Jane", "Doe" });
using (FileStream streamIn = new FileStream(MyDir + "Mail merge.doc", FileMode.Open, FileAccess.Read))
{
Stream[] images = MailMerger.ExecuteWithRegionsToImages(streamIn, new ImageSaveOptions(SaveFormat.Png), dataTable);
images = MailMerger.ExecuteWithRegionsToImages(streamIn, new ImageSaveOptions(SaveFormat.Png), dataTable, new MailMergeOptions() { TrimWhitespaces = true });
}ExecuteWithRegionsToImages(string, ImageSaveOptions, DataSet, MailMergeOptions)
Performs mail merge from a DataSet into the document with mail merge regions and renders the result to images.
public static Stream[] ExecuteWithRegionsToImages(string inputFileName, ImageSaveOptions saveOptions, DataSet dataSet, MailMergeOptions mailMergeOptions = null)Parameters
inputFileName string
The input file name.
saveOptions ImageSaveOptions
The output’s save options.
dataSet DataSet
DataSet that contains data to be inserted into mail merge fields.
mailMergeOptions MailMergeOptions
Mail merge options.
Returns
Stream []
Examples
Shows how to do mail merge with regions operation from a DataSet and save result to images.
// There is a several ways to do mail merge with regions operation from a DataSet:
string doc = MyDir + "Mail merge with regions data set.docx";
DataTable tableCustomers = new DataTable("Customers");
tableCustomers.Columns.Add("CustomerID");
tableCustomers.Columns.Add("CustomerName");
tableCustomers.Rows.Add(new object[] { 1, "John Doe" });
tableCustomers.Rows.Add(new object[] { 2, "Jane Doe" });
DataTable tableOrders = new DataTable("Orders");
tableOrders.Columns.Add("CustomerID");
tableOrders.Columns.Add("ItemName");
tableOrders.Columns.Add("Quantity");
tableOrders.Rows.Add(new object[] { 1, "Hawaiian", 2 });
tableOrders.Rows.Add(new object[] { 2, "Pepperoni", 1 });
tableOrders.Rows.Add(new object[] { 2, "Chicago", 1 });
DataSet dataSet = new DataSet();
dataSet.Tables.Add(tableCustomers);
dataSet.Tables.Add(tableOrders);
dataSet.Relations.Add(tableCustomers.Columns["CustomerID"], tableOrders.Columns["CustomerID"]);
Stream[] images = MailMerger.ExecuteWithRegionsToImages(doc, new ImageSaveOptions(SaveFormat.Png), dataSet);
images = MailMerger.ExecuteWithRegionsToImages(doc, new ImageSaveOptions(SaveFormat.Png), dataSet, new MailMergeOptions() { TrimWhitespaces = true });ExecuteWithRegionsToImages(Stream, ImageSaveOptions, DataSet, MailMergeOptions)
Performs mail merge from a DataSet into the document with mail merge regions and renders the result to images.
public static Stream[] ExecuteWithRegionsToImages(Stream inputStream, ImageSaveOptions saveOptions, DataSet dataSet, MailMergeOptions mailMergeOptions = null)Parameters
inputStream Stream
The input file stream.
saveOptions ImageSaveOptions
The output’s save options.
dataSet DataSet
DataSet that contains data to be inserted into mail merge fields.
mailMergeOptions MailMergeOptions
Mail merge options.
Returns
Stream []
Examples
Shows how to do mail merge with regions operation from a DataSet using documents from the stream and save result to images.
// There is a several ways to do mail merge with regions operation from a DataSet using documents from the stream:
DataTable tableCustomers = new DataTable("Customers");
tableCustomers.Columns.Add("CustomerID");
tableCustomers.Columns.Add("CustomerName");
tableCustomers.Rows.Add(new object[] { 1, "John Doe" });
tableCustomers.Rows.Add(new object[] { 2, "Jane Doe" });
DataTable tableOrders = new DataTable("Orders");
tableOrders.Columns.Add("CustomerID");
tableOrders.Columns.Add("ItemName");
tableOrders.Columns.Add("Quantity");
tableOrders.Rows.Add(new object[] { 1, "Hawaiian", 2 });
tableOrders.Rows.Add(new object[] { 2, "Pepperoni", 1 });
tableOrders.Rows.Add(new object[] { 2, "Chicago", 1 });
DataSet dataSet = new DataSet();
dataSet.Tables.Add(tableCustomers);
dataSet.Tables.Add(tableOrders);
dataSet.Relations.Add(tableCustomers.Columns["CustomerID"], tableOrders.Columns["CustomerID"]);
using (FileStream streamIn = new FileStream(MyDir + "Mail merge.doc", FileMode.Open, FileAccess.Read))
{
Stream[] images = MailMerger.ExecuteWithRegionsToImages(streamIn, new ImageSaveOptions(SaveFormat.Png), dataSet);
images = MailMerger.ExecuteWithRegionsToImages(streamIn, new ImageSaveOptions(SaveFormat.Png), dataSet, new MailMergeOptions() { TrimWhitespaces = true });
}