How to format mail merge field for number using Java

Hello,


Have data being passed in as $###,###.## but would like the flexibility to display it as $###,### in the table at times. Is there any way to set number formatting in Aspose / a Word table template?

Any help/guidance appreciated!

Hi Rick,

Please accept my apologies for late response.

Thanks for your query. In your case, you can simply modify the existing number format switch by using the following code snippet:

Document doc = new Document("C:\\temp\\test.docx");

Node[] starts = doc.getChildNodes(NodeType.FIELD_START, true).toArray();

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

{

FieldStart start = (FieldStart)starts[i];

if (start.getFieldType() == FieldType.FIELD_MERGE_FIELD)

{

Run fieldCode = (Run)start.getNextSibling();

fieldCode.setText(fieldCode.getText().replace("###,###.##", "###,###"));

}

}

Hope this answers your query. Please let us know, If you have any more queries.