Click or drag to resize

DocumentCoreMailMerge Property

Gets a MailMerge object that represents the mail merge functionality for the document.

Namespace: SautinSoft.Document
Assembly: SautinSoft.Document (in SautinSoft.Document.dll) Version: 2024.7.18
Syntax
public MailMerge MailMerge { get; }

Property Value

MailMerge
Remarks
Example
Generates 5 envelopes 'Happy New Year' for Simpson family using the one template using C#
using System;
using System.IO;
using SautinSoft.Document;

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

            MailMergeSimpleEnvelope();
        }

        /// <summary>
        /// Generates 5 envelopes "Happy New Year" for Simpson family using the one template.
        /// </summary>
        /// <remarks>
        /// See details at: https://sautinsoft.com/products/document/help/net/developer-guide/mail-merge-simple-report-net-csharp-vb.php
        /// </remarks>
        public static void MailMergeSimpleEnvelope()
        {
            string templatePath = @"..\..\..\envelope-template.docx";
            string resultPath = "Simpson-family.docx";

            DocumentCore dc = DocumentCore.Load(templatePath);

            var dataSource = new[] { new { Name = "Homer", FamilyName = "Simpson" },
                                new { Name = "Marge ", FamilyName = "Simpson" },
                                new { Name = "Bart", FamilyName = "Simpson" },
                                new { Name = "Lisa", FamilyName = "Simpson" },
                                new { Name = "Maggie", FamilyName = "Simpson" }};

            dc.MailMerge.Execute(dataSource);
            dc.Save(resultPath);

            // Open the result for demonstration purposes.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(resultPath) { UseShellExecute = true });
        }
    }
}
Generates 5 envelopes 'Happy New Year' for Simpson family using the one template using VB.Net
Option Infer On

Imports System
Imports System.IO
Imports SautinSoft.Document
Module Sample
    Sub Main()
        MailMergeSimpleEnvelope()
    End Sub
    ''' Get your free 100-day key here:   
    ''' https://sautinsoft.com/start-for-free/
    ''' <summary>
    ''' Generates 5 envelopes "Happy New Year" for Simpson family using the one template.
    ''' </summary>
    ''' <remarks>
    ''' See details at: https://sautinsoft.com/products/document/help/net/developer-guide/mail-merge-simple-report-net-csharp-vb.php
    ''' </remarks>
    Sub MailMergeSimpleEnvelope()
        Dim templatePath As String = "..\..\..\envelope-template.docx"
        Dim resultPath As String = "Simpson-family.docx"

        Dim dc As DocumentCore = DocumentCore.Load(templatePath)

        Dim dataSource = {
            New With {
                Key .Name = "Homer",
                Key .FamilyName = "Simpson"
            },
            New With {
                Key .Name = "Marge ",
                Key .FamilyName = "Simpson"
            },
            New With {
                Key .Name = "Bart",
                Key .FamilyName = "Simpson"
            },
            New With {
                Key .Name = "Lisa",
                Key .FamilyName = "Simpson"
            },
            New With {
                Key .Name = "Maggie",
                Key .FamilyName = "Simpson"
            }
        }

        dc.MailMerge.Execute(dataSource)
        dc.Save(resultPath)

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

End Module
See Also