Articles in this section
Category / Section

How to mail merge Word document in Docker

4 mins read

Mail merge is a process of merging data from a data source to Word template document. The Syncfusion Essential DocIO is a .NET Core Word library used to generate reports like invoice, payroll, letter, and more by performing mail merge faster in a batch process without Microsoft Word or interop dependencies. Using this library, you can mail merge Word document in Docker.

Steps to mail merge Word document in docker programmatically:

  1. Create a new C# ASP.NET Core web application project. Create new ASP.NET Core project in visual studio
  2. Select the project template with Model-View-Controller and enable the docker support. Select the target OS (Windows or Linux) based on the requirement. In this article, Linux has been used as Target OS. Select Web application and Docker support details
  3. Install the Syncfusion.DocIO.Net.Core NuGet package as a reference to your .NET Core project from NuGet.org. Install Syncfusion.DocIO.Net.Core Nuget packages
  4. Add a new button (Create Document) in the Index.cshtml as shown below.
    @{Html.BeginForm("CreateDocument", "Home", FormMethod.Get);
    {
    <div>
         <input type="submit" value="Create Document" style="width:150px; height:27px" />
    </div>
    }
    Html.EndForm();
    }
    
  1. Include the following namespaces in the HomeController.cs file.
    using System;
    using Syncfusion.DocIO.DLS;
    using Syncfusion.DocIO;
    using System.IO;
    
  1. Add a new action method CreateDocument in HomeController.cs and include the following code snippet to create a PDF file and download it.
    //Opens the Word template document
    FileStream fileStreamPath = new FileStream(@"Data/Letter Formatting.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
    using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx))
    {
        string[] fieldNames = { "ContactName", "CompanyName", "Address", "City", "Country", "Phone"};
        string[] fieldValues = { "Nancy Davolio", "Syncfusion", "507 - 20th Ave. E.Apt. 2A", "Seattle, WA", "USA", "(206) 555-9857-x5467" };
        //Performs the mail merge
        document.MailMerge.Execute(fieldNames, fieldValues);
        //Saves the Word document to MemoryStream
        MemoryStream stream = new MemoryStream();
        document.Save(stream, FormatType.Docx);
        stream.Position = 0;
        //Download Word document in the browser
        return File(stream, "application/msword", "Result.docx");
    }
    

 

A complete working example of how to mail merge Word document in Docker can be downloaded from mail merge Word document.zip.

By executing the program, you will get the Word document from docker as follows. Mail merge output Word document

Take a moment to peruse the documentation, where you will find basic Word document processing options along with features like mail merge, merge and split documents, find and replace text in the Word document, protect the Word documents, and most importantly PDF and Image conversions with code examples.

Explore more about the rich set of Syncfusion Word Framework features.

See Also:

Mail merge Word document in ASP.NET Core

Mail merge Word document in Linux

Note:

Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer to link to learn about generating and registering Syncfusion license key in your application to use the components without trial message.

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied