Create docx using Mail merge in Java

High-speed Java library to execute Mail merge operation for docx templates and data from custom data source

Our solution provides a powerful platform independent API. Use our Mail merge document API to develop high-level software for Java platform. This is a powerful software solution for merging templates in Word and PDF formats and data from custom data sources and further exporting the result to DOCX, PDF, HTML and other popular formats using Java.

View code snippet

Mail merge mustache in Java

Powerful Java library to use mail merge operation with mustache template and user data.

This Java SDK allows you to use Mustache templates based on the Mustache syntax and execute mail merge operations on this logic-less template to fill the document with data from various data sources. You can export the result into the required document format: DOCX, PDF, HTML and other popular formats using Java.

Mail merge with logic-less templates using Java

Mustache is an alternative syntax for mail merge templates that consists of tags. To create a mustache template, use tags specified by the double braces as follows:

{{FirstName}}

In this case, you can find such tags inside the template and replace them with values determined by the key inside the tag. It is called logic-less templates because there are no if statements, else clauses, or for loops.

Mustache syntax is the only option that can be used with HTML or TXT templates that do not contain any fields. This means that with some template formats, such as Word templates, you can use both fields and mustache syntax, and with others, such as HTML or TXT, only mustache template syntax.

You can try our solution to perform mail merge operation with a mustache template in Java. After running the code, export the mail merge result using Java to a convenient file format such as DOCX or PDF:

Execute a Mail merge operation using docx template in Java
Upload a Mail merge template
Run code
Select the target format from the list
import com.aspose.words.*;

String[] fields = new String[]
{
};
Object[] values = new Object[]
{
};

Document doc = new Document("Input.docx");
doc.getMailMerge().setUseNonMergeFields(true);
doc.getMailMerge().execute(fields, values);
doc.save("Output.docx");
Run code

How to use Mail merge in docx files

  1. Install Aspose.Words for Java.
  2. Add a library reference (import the library) to your Java project.
  3. Create a docx merge template with merge fields.
  4. Open the template file in Java.
  5. Call the execute() method, passing the merge fields and their values there.
  6. Call the Save() method, passing an output filename with required extension.
  7. Get the result of Mail merge operation as Word file.

Java library to use Mail merge in docx

We host our Java packages in Maven repositories. 'Aspose.Words for Java' is a common JAR file containing byte-code. Please follow the step-by-step instructions on how to install it to your Java developer environment.

System Requirements

Java SE 7 and more recent Java versions are supported. We also provide a separate package for Java SE 6 in case you are obliged to use this outdated JRE.

Our Java package is cross-platform and runs on all operating systems with JVM implementation, including Microsoft Windows, Linux, macOS, Android and iOS.

For information on optional package dependencies, such as JogAmp JOGL, Harfbuzz font engine, Java Advanced Imaging JAI, please refer to Product Documentation.

Other supported file formats

You can perform Mail merge operation for other file formats:

5%

Subscribe to Aspose Product Updates

Get monthly newsletters and offers directly delivered to your mailbox.

© Aspose Pty Ltd 2001-2024. All Rights Reserved.