Mail Merge

Agreement Start Date:
Agreement End Date:
Agreement Extension Date:
Documentation Start Date:
Documentation End Date:
downloads
  • 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();
        doc.loadFromFile(docFile);

        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());
            calendar.add(Calendar.YEAR,data);
            dateList.add(format.format(calendar.getTime()));
        }
        String[] values =new String[dateList.size()];
        dateList.toArray(values);
        
        String []fields={
                "SubGrantPAStartDateValue",
                "SubGrantPAEndDateValue",
                "SubGrantPAExtensionDateValue",
                "SubGrantPSStartDateValue",
                "SubGrantPSEndDateValue"
        };
        doc.getMailMerge().execute(fields,values);
        doc.saveToFile(resultFilePath, FileFormat.Docx);
    }
}
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 function you want, please request a free demo from us.