Free Support Forum - aspose.com

Error on MailMerge with Dates

I have an query what returns some data with an Date, the date is for example “08/05/2013 00:00:00,0” (dd/MM/yyyy)

I use the ResultSet to Merge it with my Template!
The Field for the Date is formattet in this way
"<span style=“font-size:10.0pt;font-family:
“Times New Roman”,“serif”;mso-fareast-font-family:“Times New Roman”;mso-ansi-language:
DE;mso-fareast-language:EN-US;mso-bidi-language:AR-SA” lang=“DE”>“dd.MM.yyyy”
* MERGEFORMAT

"

The Result now has the wrong Date, it is one day before my date!
The problem is the date at midnight which will be handled as day before.

So where is the problem? MailMerge? Aspose Words? Formatting in Doc?


Here my example code and my Template and Result


String sqlQuery = “SELECT 21 AS TIBO_ID, 111111 AS VEIC_ID, ‘XXXXXX’ AS VEIC_TARGA, ‘Euro 2 Verde’ AS TIBO_DENOMINAZIONE_I, NULL AS VEBO_PERSONALIZZAZIONE, to_date(‘08/05/2013 00000’, ‘dd/MM/yyyy SSSSS’) AS BOLL_DATA_PRODUZIONE_INFORMAT, ‘MCTC’ AS VEIC_FONTE_DATI, ‘Persona’ AS TIBO_DESTINATARIO, to_date(‘08/05/2013 00000’, ‘dd/MM/yyyy SSSSS’) AS BOLL_DATA_ELABORAZIONE, ‘Benzina’ AS ALIMENTAZIONE, ‘Leggero’ AS AMBITO_DIRETTIVA, ‘Valido’ as BOLL_STATO FROM DUAL”;

DataSet dataSet = new DataSet();

DataTable dataTable = new DataTable(DBConnection.getResultSet(connection, sqlQuery), “Estrazione”);
dataSet.getTables().add(dataTable);

doc.getMailMerge().executeWithRegions(dataSet);

Hi Michael,

Thanks for your inquiry. Perhaps, you are using an older version of Aspose.Words; as with Aspose.Words v13.4.0, I am unable to reproduce this problem on my side. I would suggest you please upgrade to the latest version of Aspose.Words i.e. v13.4.0 and let us know how it goes on your side. I hope, this will help.

Moreover, I suggest you please read following documentation link for your kind reference.
http://www.aspose.com/docs/display/wordsjava/How+to+Update+Fields

Hi, infact with v. 13.4.0 the problem is not reproducable so the problem is on aspose side! The last version I can use is the version 11.2.0

In next time we have to buy the AsposeTotal .Net version for about 25.000 $
So for me is difficult to explain my boss why I need to buy an other new JAVA license.

I can do a workaround on my select, I can put the time always to 11 or 12 o’clock. Is there another workaround from aspose side? Or template side?

I have to check al my works if there is somewhere the problem with this dates!

thx
Michael

Hi Michael,

Thanks for your inquiry. In your case, I suggest you please implement IFieldMergingCallback as shown in following code snippet. You may need to modify your code in fieldMerging method for date issue. Please check the code examples at following documentation link for your kind reference. Hope this helps you.
http://www.aspose.com/docs/display/wordsjava/IFieldMergingCallback


public class MailMerge_Test implements IFieldMergingCallback {

private DocumentBuilder mBuilder;

public void fieldMerging(FieldMergingArgs e) throws Exception {

if (mBuilder == null) {

mBuilder = new DocumentBuilder(e.getDocument());

}

if (e.getFieldName().equals("BOLL_DATA_PRODUZIONE_INFORMAT")) {

mBuilder.moveToMergeField(e.getDocumentFieldName());

mBuilder.write(e.getFieldValue().toString());

}

}

public void imageFieldMerging(ImageFieldMergingArgs args) throws Exception {

}

}