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

Free Support Forum - aspose.com

Creating Mail Merge Template

Hi,
When a mail template (.doc/.docx) is opened and saved to disk using the html option with apsose, is there a way to maintain the merge fields if that html file was convered back to a document. (or is that info lost - just text etc is saved) Say we wanted to allow a user to edit the template as html first in a browser (without word), so we convert doc to html, allow edit, then save html back to doc and do the mail merge. Just wondering if this is possible.
Can we use aspose to create a mail merge template using DocumentBuilder? (insert mail merge fields etc)
Thanks,
Eamonn

Hi
Thanks for your request. You can use the same technique as described here:
https://forum.aspose.com/t/113953
But with the new versions of Aspose.Words you will have to modify code a little. You should use IReplacingCallback instead of ReplaceEvaluator:
https://reference.aspose.com/words/net/aspose.words.replacing/ireplacingcallback/
Best regards,

Hi,
Is there any chance to get an up to date version of this for java to test, it seems to be very old so I’m assuming a lot has changed.
Thanks,
Eamonn

Hello
Thanks for your request. You can download the latest version of Aspose.Words for Java from here:
https://releases.aspose.com/words/java
If you want to test Aspose products without the evaluation version limitations, you can request a 30-day Temporary License. Please refer to
https://purchase.aspose.com/temporary-license
Best regards,

Hi,
I’m using the latest jar file and have a 30 day trial, what I want is an up to date java code to implement this technique?
https://releases.aspose.com/words/java
Thnaks,

Hi
Thanks for your inquiry. I think in this case you should just change your code to use IReplacingCallback instead of ReplaceEvaluator. Please see the following link for more information:
https://reference.aspose.com/words/java/com.aspose.words/IReplacingCallback
Please let me know in case of any issues. I will be glad to help you.
Best regards,

Hi,
How do I get this value now (from previous old sample)?

string fieldName = e.Match.Groups["FieldName"].Value;

Do I use String fieldName = e.getMatch()?
Also I get a pattern exception on this

doc.getRange().replace(Pattern.compile("«(?.*?)»"), new KeepMergefields(), false);

Can you help. I need to implement the technique in Java, I need something quick so we can test some files.
Thanks,
Eamonn

Hi
Thanks for your request. You should modify your pattern as shown below because in java you cannot use named groups:

doc.getRange().replace(Pattern.compile("«(.*?)»"), new KeepMergefields(), false);

Then you can access group value by index:

String fieldName = e.getMatch().group(1).toString();

Best regards,

Really appreciate that, thanks.