Mail Merge not carrying the date formats on generated pdf and word document

In the template I have formatted a mail merge field as shown below:

{ MERGEFIELD Static_Date @ "dd/MM/yyyy"}

The output I was expecting to see after the mail merge was 18/02/2016 on the generated PDF/WORD file but it still shows 2016-02-18 00:00:00.0.

It is not carrying the format to the generated PDF/Word file.

Is there any setting we need to make in the code to get this working?

Hi John,

Thanks for your inquiry. We have tested the scenario using latest version of Aspose.Words for Java 16.1.0 and have not found the shared issue. We have attached the code, input and output documents with this post for your kind reference.

We would suggest you please upgrade to the latest version of Aspose.Words. You can download it from the following link. Hope, this helps.

Download latest version of Aspose,Words for Java

If you still face problem, please attach your input Word document here for testing. We will investigate the issue on our side and provide you more information.

Document doc = new Document(MyDir + "in.docx");
doc.getMailMerge().execute(new String[] { "Static_Date" }, new Object[] { new Date() });
doc.save(MyDir + "Out.docx");
doc.save(MyDir + "Out.pdf");

Hi Tahir,

We are currently using version aspose-words-15.3.0-jdk16.jar. We are in process of getting our license renewed so that we can upgrade to the latest version of aspose. Since this might take some time, and even if we get this we will have to do regression test before we go live.

Is there any work around in the version (aspose-words-15.3.0-jdk16.jar) that we are using to make this work? It would be really helpful as we have to go live in a week or two.

I will still test with the latest version to check if the issue is resolved, but would appreciate if we can get a work around in the version we are using.

Thanks,
John

Hi Tahir,

We tried the latest jar, but it did not work. Seems like you misunderstood the issue we are having. When we do the mail merge for a single row in the report, it works fine on the word template. But when we save the document for download in word or pdf it does not work.

For you reference I have attached the MailMerge.png file (word document) where we have the format of the field added to the date column. The outcome after the mail merge on the single row gives us the output as attached in MailMergeOutput.png

When we do the mail merge for all rows and save the document in pdf or word, on downloading we do not see the format being carried over. (Attached the files for reference - date format issue aspose.docx and date format issue aspose.pdf)

Looks like there is some issue with our code. Can you please check to see if we have missed something. The code snippet we have is below:

Document templateDocument = new Document(templatePath);
Document finalDoc = null;
if (dataTable != null)
{
    String fileNamePrefix = rootPath + File.separator + mergeDocumentName;
    String finalDocName = fileNamePrefix + ClientReportingConstants.WORD_DOCUMENT_EXTN;

    String tempFile = fileNamePrefix + "_temp" + ClientReportingConstants.WORD_DOCUMENT_EXTN;

    // Merging data into temporary files, then into the finalMergedDoc and deleting the temporary files
    finalDoc = (Document)templateDocument.deepClone(true);
    mapColumnNames(dataTable, finalDoc);
    //check time required to execute if property is true
    boolean parseHtml = PropertyConfigurator.getProperty("com.per.parseHtml") != null ? Boolean.parseBoolean(PropertyConfigurator.getProperty("com.per.parseHtml")) : false;
    if (parseHtml)
    {
        stripHtmlValues(dataTable);
    }
    finalDoc.updateFields();
    finalDoc.getMailMerge().setFieldMergingCallback(new FieldMergingCallback());
    finalDoc.getMailMerge().setCleanupOptions(MailMergeCleanupOptions.REMOVE_CONTAINING_FIELDS);

    // finalDoc.joinRunsWithSameFormatting();

    finalDoc.getMailMerge().execute(dataTable);
    new ClientReportingHelper().removeEmptyRowFromDocument(finalDoc);

    finalDoc.save(finalDocName);
    if (generatePdf)
    {
        String finalPDFName = fileNamePrefix + ClientReportingConstants.PDF_DOCUMENT_EXTN;
        finalDoc.save(finalPDFName);
        // setting order templates to null and mergetemplate order to 0 as this method will be called for merge without static templates 
        // mergePdfDocumentForDownload(null, finalPDFName,0);
    }
}

Hi John,

Thanks for your inquiry.

john.beatty@citi.com:

Is there any work around in the version (aspose-words-15.3.0-jdk16.jar) that we are using to make this work? It would be really helpful as we have to go live in a week or two.

Unfortunately, we don’t provide support for older releases of Aspose.Words. Please note that we do not provide any fixes or patches for old versions of Aspose products either. All fixes and new features are always added into new versions of our products. So, you will have to upgrade if you need new features or fixes.

john.beatty@citi.com:

We tried the latest jar, but it did not work. Seems like you misunderstood the issue we are having. When we do the mail merge for a single row in the report, it works fine on the word template. But when we save the document for download in word or pdf it does not work.

We have tested the scenario using com.aspose.words.net.System.Data.DataTable as data source and have not found the shared issue.

To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document
  • Please create a standalone console application (source code without compilation errors) that helps us reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we’ll start investigation into your issue and provide you more information. Thanks for your cooperation.

Attached the Input Word Document -asposeMailMerge.docx

Attached the standalone console application as well. - ReportGenerator.java (remove .txt)

Thanks,
John

Hi John,

Thanks for your inquiry. In your code (ReportGenerator.java), you are not loading input document into Aspose.Words.Document. You are using MailMerge.Execute method (String[], Object[]) to perform a mail merge operation for a single record. However, in your this post you reported that the issue is with MailMerge.Execute method (DataTable).

We have tested the scenario using MailMerge.Execute method (String[], Object[]) method and have not found the shared issue. Please check the attached output Docx and Pdf.

As per my understanding, you are facing issue with MailMerge.Execute method (DataTable). It would be great it you please share standalone console application (source code without compilation errors) that helps us reproduce your problem on our end and attach it here for testing.