After setting the mergefield in Microsoft Word to be bold and font size 12, I ran my Java code with Aspose Words. However, only the first two words are in bold and font size 12 while the rest were not.
Eg. mergefield in word: <>
value from java: “This goes into myFieldName”
Only “This” and “goes” were in bold and font size 12
“into” and “myFieldName” were not in bold and font size 14 instead
For example in Word, i have Insert > Quick Parts > Field > MergeField > myFieldName > Preserve formatting during updates > OK. I then keep the font as Times New Roman, bold the myFieldName and set it to font size 12. After saving the Word document, i closed it.
Inside Java, i have the following as example:
String myFieldValue = “This goes into myFieldName”;
Document doc = new Document(reportDir + templateFilename);
doc.getMailMerge().execute(new String[] {“myFieldName”}, new Object[] {myFieldValue});
doc.save(reportDir + filename + “.docx”);
Please advise. I have created a Microsoft Word template with several mergefields created. As such the advice given in applying custom formatting is not very efficient as alot of mergefields were affected.
Using the following:
Eclipse Java EE IDE for Web Developers (Photon Release 4.8.0)
Microsoft Office Word 2007
Java Version 8 Update 101 (build 1.8.0_101-b13)
Thanks for your inquiry. To ensure a timely and accurate response, please ZIP and attach the following resources here for testing:
Your simplified input Word document
Aspose.Words 18.9 generated output DOCX file showing the undesired behavior
Your expected DOCX document showing the correct output. You can create expected document by using Microsoft Word.
As soon as you get these pieces of information ready, we will start further investigation into your issue and provide you more information. Thanks for your cooperation.
Thanks for the quick response! However, that is not what i need.
I need some merge fields to be in bold, while some with underline. There are also different parts of the document which requires different font sizes. Is it possible to provide me a workaround with more merge fields examples (besides “Company”) so that i can understand how each merge field is formatted?
With respect to the same sample documents i have sent you, i need
In my actual document, i have more merge fields than these… Is there a way where it detects the format of each merge field in the Microsoft Word template and produces the word(s) in that particular format without me having to fix/dictate the formats beforehand?
Thank you for your reply awais! It works perfectly!
Just checking, why did you use
“Node nextNode = currentNode.nextPreOrder(currentNode.getDocument());”
instead of
“Node nextNode = currentNode.getNextSibling();”?