Hi
We want to subtract two merge fields:
i.e: «Total_ListPrice_Sum» - «Total_Discount»
20 000 USD - 2000 USD = 18 000 USD
This two merge fields are tags from our CRM system that gets information from our system into word.
Is it possible to subtract this fields?
Hi,
Thanks for your interest in Aspose.Words. You can use formula field in your template Word document as shown in attached document. You can then populate these merge fields with data by using the code like below:
Document doc = new Document(“C:\Temp\in.docx”);
doc.getMailMerge().execute(new String[]{“Total_ListPrice_Sum”, “Total_Discount”}, new String[]{“5”, “2”} );
doc.save(“C:\Temp\out.pdf”);
Best regards,
Hi,
Thanks for your information. Its working now
One other question related to this. If I do this subtraction it doesn’t format the numbers. I want it to format it like currency i.e. 1 000 000.00
I have google for answers but can´t get it right. It this correct:
{ =«Total_ListPrice_Sum»-«Total_Discount» # ,0.00}
Best regards,
Joel
Hi Joel,
Thanks for your inquiry. Please use the following switch which displays the results with a currency sign and thousands separators. for example, $14,786.17:
# "$#,##0.00"
I hope, this helps.
Best regards,
I see, thanks for the information.
It is not possible to have spaces between the numbers? i.e. €1 000 000
Hi Joel,
Thanks for your inquiry. You can display currency in groups of three digits separated by white space character by using the following number format:
# “€# ### ###”
Also, I would suggest you please visit the following page for more details:
Best regards,
Hi again,
We have problem when we subtract two merge fields.
The originally code: = {«Order_Total_NC» - «Order_Discount_NC»}
When word opens from our system we get this: !Syntaxfel,
« (Swedish for syntax error)
If we open the field we get {= 23526 - 100}, which is correct numbers.
What we need to do is to update field to get the correct numbers in our word document.
Any solution for this, so the correct numbers displays in word without having to press update field?
Hi Joel,
Thanks for your inquiry. Please attach 1) your input Word document, 2) output document showing the undesired behavior and 3) code to reproduce the issue on my end here for testing. I will investigate the issue on my side and provide you more information.
Best regards,
Hi,
I have found the problem.
I missed to use: doc.updateFields(); in the end of the code.