We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Aspose Words - Creating reports (Java)

Hello Aspose Team,

We want to use Aspose to create simple docx files based on a constructed template.
The template would have a couple of fields to be dynamically filled, but nothing fancy. Just simple strings.

Looking on this subject we understood that there are two way of doing this: Mail Merge or LINQ, and the documentation about both in the docs is a little extensive.

As we are not familiar with either technology, we wanted to know which should we use, or what are the differences. And, if possible, a “getting started code” would be awesome. Like I told, the case scenario is very simple, so just a little example would put us on track.

Thanks in advance,

Vinicius Paiva


In your case, the standard ‘Mail Merge and Reporting’ of Aspose.Words will be enough to meet your requirement. Please see these input/output Word documents (Reporting-Template-Syntax.zip (18.6 KB)) and try running the following code:

Document doc = new Document("E:\\temp\\reporting-template.docx");

// Standard Mail Merge fills the values in 'merge fields'.
doc.getMailMerge().execute(new String[]{"GENDER"}, new Object[]{"MALE"});

// Standard Mail Merge but fills the values in 'plain text markers' instead of 'merge fields'.
doc.getMailMerge().execute(new String[]{"GENDER"}, new Object[]{"FEMALE"});

// LINQ Reporting Engine example code to fill values LINQ Reporting Synatx
DataTable dt = new DataTable("tbl");
DataColumn dc = new DataColumn("GENDER", String.class);
DataRow dr = dt.newRow();


dr.set(0, "FEMALE");

ReportingEngine engine = new ReportingEngine();
engine.buildReport(doc, dt.getRows().get(0), "row");