Execute Mail Merge operation in Word with C# and VB.NET

Mail merge is a process of merging or importing data from a data source to a document.

Following example demonstrates how to perform a simple mail merge by importing data from an instance of an anonymous type.

Input template document also defines formatting for DateTime field using the field date/time formatting switch (\@).

To view field switches in Microsoft Word, press Alt + F9 to toggle field codes.

Field numeric switch (\#) is also supported for formatting numeric data types in the mail merge process.

Merge Fields Screenshot
Upload your file (Drag file here)
using System;
using GemBox.Document;

class Program
{
    static void Main()
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        DocumentModel document = DocumentModel.Load("%InputFileName%");

        var customer = new { CustomerName = "John", Surname = "Doe", Date = DateTime.Now };

        document.MailMerge.Execute(customer);

        document.Save("Merge Fields.%OutputFileType%");
    }
}
Imports System
Imports GemBox.Document

Module Program

    Sub Main()

        ' If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY")

        Dim document As DocumentModel = DocumentModel.Load("%InputFileName%")

        Dim customer = New With {.CustomerName = "John", .Surname = "Doe", .Date = DateTime.Now}

        document.MailMerge.Execute(customer)

        document.Save("Merge Fields.%OutputFileType%")

    End Sub

End Module

Check next example or download examples from GitHub.