Mail Merge

Agreement Start Date:
Agreement End Date:
Agreement Extension Date:
Documentation Start Date:
Documentation End Date:
  • Demo
  • Java
  • C# 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
import com.spire.doc.Document;
import com.spire.doc.FileFormat;

import java.text.SimpleDateFormat;
import java.util.ArrayList;

public class MailMargeDemo {

     public void mailMerge(String docFile, String resultFilePath) throws Exception {
        Document doc = new Document();

        SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar=Calendar.getInstance();

        ArrayList dateList=new ArrayList<>();
        int []offset={-5,5,6,-2,2};
        for(int data:offset){
            calendar.setTime(new Date());
        String[] values =new String[dateList.size()];
        String []fields={
        doc.saveToFile(resultFilePath, FileFormat.Docx);
No Matter How Big or Small Your Project is,
Any technical question related to our product, contact us at
Any question related to the purchase of product, contact us at
If you don't find the function you want, please request a free demo from us.