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

Free Support Forum - aspose.com

Mergefield function doesn't work

Hi,


I’ve a little problem when I use the aspose words merge mail function with mergefield into the word template

For example : MERGEFIELD “FORMULE_SELECT_MNT_A_HT” # “### ##0,00” doesn’t work

I expect for example “56,00” but i have “56.00” (like in the data source)

What’s wrong ?

Thanks

Regards,
Julien
Hi Julien,

Thanks for your inquiry. To ensure a timely and accurate response please supply us with the following information, if you cannot supply us with this information we will not be able to investigate your issue and raise a ticket.

What environment are you running on?

  • OS (Windows Version or Linux Version)
  • Architecture (32 / 64 bit)
  • JDK version
  • Provide information about your specific culture, such as the name of the culture, language and country/region.
  • Please supply us with the code from your application that is causing the issue
  • Please supply us with the input document that is causing the issue

As soon as you get these pieces of information to us we'll start our investigation into your issue.
Many thanks,

Thanks for you answer


- OS server : Linux Debian Lenny (V5) 64 bits
- JDK 1.6
- We are french users (north of France)

The code of the application (mail merge)

Document lettreType = new Document("/root/test.doc"); // TEMPLATE
Document dstDoc = (Document) lettreType.deepClone(true);
dstDoc.getMailMerge().execute(sourceDeDonnees.getTabStringForFieldsName(), sourceDeDonnees.getTabObjectForValues());
dstDoc.save("/root/test_.doc");

For information : sourceDeDonnees.getTabStringForFieldsName() return something a String[] of all merge fields (field1, field2 …) and sourceDeDonnees.getTabObjectForValues() give the same thing but with the data of merge fields.

Attachment : the word template document (DevisWebAction.doc)

The problem occur on page 2 :

Prime Annuelle HT :

«FORMULE_SELECT_MNT_A_HT»


Look at the "mergefield.png" attachment, this is the problem i've mentionned earlier.

If in the data source, on "FORMULE_SELECT_MNT_A_HT", we put a value like "65.00", the result after using merge mail function with Aspose gives "65.00" while it should be "65,00" with the word function.

I hope you'll understand ;)

Regards,
Julien

In fact, I’m talking about formating merged data (like http://office.microsoft.com/en-us/word-help/format-merged-data-HP005187180.aspx)

After many other try


The merged data commutator \b works, for example MERGEFIELD CHAMP \b « TEST » gives TEST and the data of field "CHAMP"

The merged data commutator # (numeric) doesn’t work like explain before

Hi Julien,


Thanks for sharing the details. I have tested the scenario and have not found the number formatting issue while using latest version of Aspose.Words for Java. I would suggest you please upgrade to the latest version (v13.2.0) from here and let us know how it goes on your side. Please read following documentation link for your kind reference.
http://www.aspose.com/docs/display/wordsjava/How+to+Update+Fields

I’ve allready the last version.


Could you provide me your tests (word template and data source) please ?

Hi Julien,


Thanks for your inquiry. I have used the following code snippet with your document (DevisWebAction.doc). I have attached the output document with this post for your kind reference.

To control the locale used during field calculation, just set the Locale.setDefault property to a locale of your choice before invoking field calculation. Please read following article.
http://www.aspose.com/docs/display/wordsjava/How+to+Update+Fields

<span style=“font-size:
10.0pt;font-family:“Courier New”;mso-no-proof:yes”>Locale currentCulture =
Locale.getDefault();<o:p></o:p>

// Set Locale to French language so numbers are formatted using this culture during mail merge.

Locale.setDefault(new Locale("fr", "FR"));

Document doc2 = new Document(MyDir + "DevisWebAction.doc");

Document doc = (Document)doc2.deepClone(true);

String[] fieldNames = new String[] { "FORMULE_SELECT_MNT_A_HT", "FORMULE_SELECT_MNT_A_TAXES", "FORMULE_SELECT_MNT_A_TTC" };

Object[] fieldValues = new Object[] { 65.00, 85.25, 75.0 };

doc.getMailMerge().execute(fieldNames, fieldValues);

doc.save(MyDir + "AsposeOut-Java.docx");

Locale.setDefault(currentCulture);

Ok I understand now.


It’s because you used

String[] fieldNames = new String[] { “FORMULE_SELECT_MNT_A_HT”,“FORMULE_SELECT_MNT_A_TAXES”, “FORMULE_SELECT_MNT_A_TTC” };

Object[] fieldValues = new Object[] { 65.00, 85.25, 75.0 };


And we used


String[] fieldNames = new String[] { “FORMULE_SELECT_MNT_A_HT”,“FORMULE_SELECT_MNT_A_TAXES”, “FORMULE_SELECT_MNT_A_TTC” };<o:p></o:p>

Object[] fieldValues = new Object[] { “65.00”, “85.25”, “75.0” };


So aspose don’t think theses are numeric but alphabetic.


There is no way to make this work with “” arround numeric ?

Regards,

Julien

Could you fixe Aspose to make fields even with “” to be consider as numeric if they are ?


Because the only solution to makes this works with this version is to use the the Object[] and not the XML …

Thanks a lot

Hi Julien,


Thanks for your inquiry. When a string value is password to mail merge engine, that value is considered as string not numeric.

I am in communication with the development team and will update you as soon as I have information on this.

Ok thanks a lot.


Do you think this will be long or not ? Because this is the last problem we have before buying this API.

Regards
Hi Julien,

Thanks for your inquiry. I will update you via this forum thread once I get response from our development team.
jrombouts:
The code of the application (mail merge)

Document lettreType = new Document("/root/test.doc"); // TEMPLATE
Document dstDoc = (Document) lettreType.deepClone(true);
dstDoc.getMailMerge().execute(sourceDeDonnees.getTabStringForFieldsName(), sourceDeDonnees.getTabObjectForValues());
dstDoc.save("/root/test_.doc");
For information : sourceDeDonnees.getTabStringForFieldsName() return something a String[] of all merge fields (field1, field2 ....) and sourceDeDonnees.getTabObjectForValues() give the same thing but with the data of merge fields.
In your case, please convert the numeric values of your string array items to double as shown in following code snippet. Hope this helps you. Please let us know if you have any more queries.

Locale currentCulture = Locale.getDefault();

// Set Locale to French language so numbers are formatted using this culture during mail merge.

Locale.setDefault(new Locale("fr", "FR"));

Document doc = new Document(MyDir + "in.docx");

String[] fieldNames = new String[] { "field1", "field2", "field3" };

String[] values = new String[] { "65.00", "85.23", "string value" };

Object[] fieldValues = new Object[values.length];

for (int i = 0; i < fieldValues.length; i++) {

try {

fieldValues[i] = Double.valueOf(values[i].toString());

} catch (Exception e) {

fieldValues[i] = values[i].toString();

System.out.println(values[i]);

}

}

doc.getMailMerge().execute(fieldNames, fieldValues);

doc.save(MyDir + "Out.docx");

Locale.setDefault(currentCulture);


Hi Julien,


Further to my last post, I have logged this issue as WORDSNET-8001 in our issue tracking system. I have linked this forum thread to the same issue and you will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

Hi Julien,


Thanks for your patience. Regarding WORDSNET-8001, it is to inform you that on further investigation our development team came to know that they won’t be able to implement the fix to your issue. Most likely, your issue will be closed with ‘‘Won’t Fix’’ resolution. Please let me know if I can be of any further assistance.