Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Wed Mar 02, 2022 4:23 pm

Does the Spire.Doc Java library allow formatting to be applied to mergefields like the following:

Code: Select all
{ MERGEFIELD price \* MERGEFORMAT \# £,0.00 }


In the above example the input value of price may be 10.30000000 and the output should be £10.30.

I have searched the documentation and forum for this functionality and can't find anything.

cjericho
 
Posts: 17
Joined: Wed Jan 19, 2022 11:38 am

Thu Mar 03, 2022 2:41 am

Hello,

Thank you for your inquiry.
Yes, our spire.doc for java allows formatting to be applied to mergefields. I tested your mergefield code and found that the formatting applied didn't work. After investigation, I found that your merge field code is incorrect, please modify it to the following code.
Code: Select all
{ MERGEFIELD  "price"  \# £,0.00 }

If there is any question, just feel free to contact us.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1651
Joined: Wed Apr 07, 2021 2:50 am

Thu Mar 03, 2022 1:30 pm

Thanks for your reply, it was a help but I am now experiencing a related issue.

I have the currency flag working for simple fields, like this:

Code: Select all
price = 10.0000; { MERGEFIELD price \# £#,##0.00 } => £10.00


However, if I sum up fields the flag seems to add a random space between the currency symbol and the amount, see below for an example:

Code: Select all
price=10.0000; tax=2.0000; discount=-1.0000; {={ MERGEFIELD price }+{ MERGEFIELD tax }+{ MERGEFIELD discount } \# £#,##0.00 } => £ 11.00


Do you know why this is happening?

cjericho
 
Posts: 17
Joined: Wed Jan 19, 2022 11:38 am

Fri Mar 04, 2022 7:49 am

Hello,

Thanks for your feedback.
The merge field code you provided is not recognized in MS Word (as shown in the screenshot). To help us investigate your issue further, please provide the following information. You could attach them here or send them to us via email (support@e-iceblue.com). Thanks in advance.
1) Your input file (if any).
2) Your complete test code.
3) The JDK version you are using, such as JDK1.8 .
4) Your test environment, such as OS info (E.g. Windows 7, 64-bit) and region setting (E.g. China, Chinese).

Sincerely,
Annika
E-iceblue support team
screenshot .jpg
User avatar

Annika.Zhou
 
Posts: 1651
Joined: Wed Apr 07, 2021 2:50 am

Fri Mar 04, 2022 4:45 pm

Hi,

I have attached code that reproduces the error, an input template and also the other information requested.

1) attached
2) see below
3) openjdk 11.0.13 2021-10-19
4) Windows 10, 64-bit

Code: Select all
package SpireTest;

import com.spire.doc.Document;
import com.spire.doc.FileFormat;
import com.spire.doc.reporting.MailMergeDataTable;

import java.util.*;

public class App {
    public static void main(String[] args) throws Exception {
        Document document = new Document();
        document.loadFromFile("");

        List < InvoiceItem > invoiceItems = new ArrayList < InvoiceItem > ();
        InvoiceItem i1 = new InvoiceItem();
        i1.setProductName("Product One");
        i1.setQuantity(1);
        i1.setUnitCost(1);
        i1.setChargeAmount(10.0 d);
        i1.setTaxAmount(2.0 d);
        i1.setDiscountAmount(1.0 d);
        invoiceItems.add(i1);

        // mail merge
        document.getMailMerge().executeGroup(new MailMergeDataTable("InvoiceItems", invoiceItems));
        document.saveToFile("", FileFormat.PDF);
    }

    static class InvoiceItem {
        public String productName;
        public int quantity;
        public double unitCost;
        public double chargeAmount;
        public double taxAmount;
        public double discountAmount;

        public String getProductName() {
            return productName;
        }

        public void setProductName(String productName) {
            this.productName = productName;
        }

        public int getQuantity() {
            return quantity;
        }

        public void setQuantity(int quantity) {
            this.quantity = quantity;
        }

        public double getUnitCost() {
            return unitCost;
        }

        public void setUnitCost(double unitCost) {
            this.unitCost = unitCost;
        }

        public double getChargeAmount() {
            return chargeAmount;
        }

        public void setChargeAmount(double chargeAmount) {
            this.chargeAmount = chargeAmount;
        }

        public double getTaxAmount() {
            return taxAmount;
        }

        public void setTaxAmount(double taxAmount) {
            this.taxAmount = taxAmount;
        }

        public double getDiscountAmount() {
            return discountAmount;
        }

        public void setDiscountAmount(double discountAmount) {
            this.discountAmount = discountAmount;
        }
    }
}

cjericho
 
Posts: 17
Joined: Wed Jan 19, 2022 11:38 am

Mon Mar 07, 2022 2:29 am

Hello,

Thanks for sharing and sorry for the late reply as weekend.
I tested your case and reproduced the issue you mentioned. After further investigation, I found that the result is the same even when using MS Word to directly mail merge and then convert to PDF.
MSWord.png

Kindly note that our product follows Microsoft's rules. What is the effect of the layout generated by Microsoft, then our product is the same. Hope you can understand.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1651
Joined: Wed Apr 07, 2021 2:50 am

Mon Mar 07, 2022 9:50 am

Thanks for your help!

cjericho
 
Posts: 17
Joined: Wed Jan 19, 2022 11:38 am

Mon Mar 07, 2022 9:57 am

Hello,

You are welcome.

If you encounter other issues related to our products in the future, please feel free to contact us.

Have a nice day!

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1651
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.Doc