Mail Merge

  • Demo
  • C# source
  • VB.Net source
This demo shows you how to merge some data into a Word template. Our Spire.Doc provides also the function NestedMailMerge with which you can merge the main-table and sub-table into a Word template to get a professional report. You can get a full demo from the article How to Use Mail Merge to Create Report
No Matter How Big or Small Your Project is,
Any technical question related to our product, contact us at support@e-iceblue.com.
Any question related to the purchase of product, contact us at sales@e-iceblue.com.
If you don't find the demo you want, please contact support@e-iceblue.com for the free customized demo just for you.
using System;
using Spire.Doc;

namespace DemoOnlineCode
{
    class MailMerge
    {
        public void demoMailMerge(String docFile)
        {
            Document document = new Document(docFile, FileFormat.Auto);

            string[] values = {
                                  DateTime.Today.AddYears(-5).ToString("yyyy-MM-dd"),
                                  DateTime.Today.AddYears(5).ToString("yyyy-MM-dd"),
                                  DateTime.Today.AddYears(6).ToString("yyyy-MM-dd"),
                                  DateTime.Today.AddYears(-2).ToString("yyyy-MM-dd"),
                                  DateTime.Today.AddYears(2).ToString("yyyy-MM-dd")
                              };
            string[] fields = {
                                   "SubGrantPAStartDateValue",
                                   "SubGrantPAEndDateValue",
                                   "SubGrantPAExtensionDateValue",
                                   "SubGrantPSStartDateValue",
                                   "SubGrantPSEndDateValue"
                                 };
            document.MailMerge.Execute(fields, values);
            document.SaveToFile("demo.doc", FileFormat.Doc);

        }
    }
}
Imports Spire.Doc

Namespace DemoOnlineCode
    Class MailMerge
        Public Sub demoMailMerge(docFile As [String])
            Dim document As New Document(docFile, FileFormat.Auto)
            Dim values As String() = {
                                      DateTime.Today.AddYears(-5).ToString("yyyy-MM-dd"),
                                      DateTime.Today.AddYears(5).ToString("yyyy-MM-dd"),
                                      DateTime.Today.AddYears(6).ToString("yyyy-MM-dd"),
                                      DateTime.Today.AddYears(-2).ToString("yyyy-MM-dd"),
                                      DateTime.Today.AddYears(2).ToString("yyyy-MM-dd")
                                  }
            Dim fields As String() = {
                "SubGrantPAStartDateValue",
                "SubGrantPAEndDateValue",
                "SubGrantPAExtensionDateValue",
                "SubGrantPSStartDateValue",
                "SubGrantPSEndDateValue"
                                      }
            document.MailMerge.Execute(fields, values)
            document.SaveToFile("demo.doc", FileFormat.Doc)
        End Sub
    End Class
End Namespace