Click or drag to resize

MailMerge Class

Represents the mail merge functionality.
Inheritance Hierarchy
SystemObject
  SautinSoft.Document.MailMergingMailMerge

Namespace: SautinSoft.Document.MailMerging
Assembly: SautinSoft.Document (in SautinSoft.Document.dll) Version: 2024.1.24
Syntax
public sealed class MailMerge

The MailMerge type exposes the following members.

Properties
 NameDescription
Public propertyCode exampleClearOptions Gets or sets a set of flags that specify what items should be removed during mail merge.
Public propertyDocument Gets the owner document.
Public propertyFieldMappings Gets the mappings from field names to data source column names.
Public propertyRangeEndPrefix Gets or sets a mail merge region end prefix.
Public propertyRangeStartPrefix Gets or sets a mail merge region start prefix.
Top
Methods
 NameDescription
Public methodClearTemplate Remove all MergeFields from the current document.
Public methodCode exampleExecute(Object) Executes a mail merge operation with specified data source.
Public methodExecute(Object, String) Executes a mail merge operation with specified range name and data source.
Public methodGetMergeFieldNames Gets a collection of mail merge field names available in the document.
Public methodRemoveMergeFields Removes all mail merge related fields (MergeField, MergeRec, MergeSeq, Next and If) from the document.
Public methodRemoveMergeFields(Boolean) Removes mail merge related fields from the document.
Top
Events
 NameDescription
Public eventFieldMerging Occurs when Field is merging with data source value and can be used to customize the merging operation.
Top
Example

See Developer Guide: Generates a table report with regions based on DOCX template and XML document as data source

Generates a table report with regions based on DOCX template and XML document as data source in C#
using System;
using System.Data;
using System.IO;
using SautinSoft.Document;

namespace Sample
{
    class Sample
    {
        static void Main(string[] args)
        {
            // Get your free 30-day key here:   
            // https://sautinsoft.com/start-for-free/

            TableReportWithRegions();
        }

        /// <summary>
        /// Generates a table report with regions using XML document as a data source.
        /// </summary>
        /// <remarks>
        /// See details at: https://www.sautinsoft.com/products/document/help/net/developer-guide/mail-merge-table-report-with-regions-net-csharp-vb.php
        /// </remarks>
        public static void TableReportWithRegions()
        {
            // Create the Dataset and read the XML.
            DataSet ds = new DataSet();

            ds.ReadXml(@"..\..\..\Orders.xml");

            // Load the template document.
            string templatePath = @"..\..\..\InvoiceTemplate.docx";

            DocumentCore dc = DocumentCore.Load(templatePath);

            // Execute the mail merge.
            dc.MailMerge.Execute(ds.Tables["Order"]);

            string resultPath = "Invoices.pdf";

            // Save the output to file
            dc.Save(resultPath);

            // Open the result for demonstration purposes.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(resultPath) { UseShellExecute = true });
        }
    }
}
Generates a table report with regions based on DOCX template and XML document as data source in VB.Net
Imports System
Imports System.Data
Imports System.IO
Imports SautinSoft.Document

Namespace Sample
    Friend Class Sample
        Shared Sub Main(ByVal args() As String)
            TableReportWithRegions()
        End Sub
        ''' Get your free 30-day key here:   
        ''' https://sautinsoft.com/start-for-free/
        ''' <summary>
        ''' Generates a table report with regions using XML document as a data source.
        ''' </summary>
        ''' <remarks>
        ''' See details at: https://www.sautinsoft.com/products/document/help/net/developer-guide/mail-merge-table-report-with-regions-net-csharp-vb.php
        ''' </remarks>
        Public Shared Sub TableReportWithRegions()
            ' Create the Dataset and read the XML.
            Dim ds As New DataSet()

            ds.ReadXml("..\..\..\Orders.xml")

            ' Load the template document.
            Dim templatePath As String = "..\..\..\InvoiceTemplate.docx"

            Dim dc As DocumentCore = DocumentCore.Load(templatePath)

            ' Execute the mail merge.
            dc.MailMerge.Execute(ds.Tables("Order"))

            Dim resultPath As String = "Invoices.pdf"

            ' Save the output to file
            dc.Save(resultPath)

            ' Open the result for demonstration purposes.
            System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(resultPath) With {.UseShellExecute = True})
        End Sub
    End Class
End Namespace
See Also