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

Free Support Forum - aspose.com

Merge Fields turned into Plain Text by LibreOffice or OpenOffice - Convert Text into Real Merge Fields using C# .NET

I’m unable to use Merge Fields when document is saved from LibreOffice.
When document is saved from Microsoft Office it works but as soon as I open it under LibreOffice and save it as doc(x) The fields are not replaced.
I’m using the example from here: Mail Merge Form Fields
Please find attached the Files copied from example and file libreOfficeTemplate.doc saved using LibreOffice
My environment
OS: Ubuntu 14 x86_64
Java: 1.7.0

Hi Jakub,

Thanks for your inquiry. This is not a bug in Aspose.Words for Java. When you ‘save as’ Microsoft Word generated ‘template.doc’ with LibreOffice as well as OpenOffice, they turn merge fields into plain text that is why Aspose.Words is unable to perform mail merge because there are no merge fields in ‘libreOfficeTemplate.doc’. I think, you should contact LibreOffice support, maybe they will be able to help to resolve this problem.

Best regards,


I have a LibreOffice Template that I want to be filled with Aspose Words code.
Can I do that? Or because of what you said above, is not possible?


Hi Rafael,

Thanks for your inquiry. Could you please attach your template Word document here for testing? We will investigate the issue on our end and provide you more information.

Best regards,

Sure, here it is.
It’s in portuguese, ok?
If you have any problems with that, let me know!


Also, I’m having problem to understand how to use Fields (placeholder, mergefield) in my document template and populate a document using aspose! I have only see MailMerge examples and that’s not my case.


Hi Rafael,
Thanks for your inquiry. Well, there are no real merge fields in your sample ODT file. However, you can transform these place holders into real merge fields and then perform mail merge as normal. Here is code to transform these text place holders into real merge fields:

Document doc = new Document(getMyDir() + "oficio.odt");

doc.getRange().replace(Pattern.compile("\[\[(.*?)\]\]"), new ReplaceEvaluatorFindAndInsertMergefield(), false);

static class ReplaceEvaluatorFindAndInsertMergefield implements IReplacingCallback {

    public int replacing(ReplacingArgs e) throws Exception {
        Node currentNode = e.getMatchNode();

        // The first (and may be the only) run can contain text before the match,
        // in this case it is necessary to split the run.
        if (e.getMatchOffset() > 0)
            currentNode = SplitRun((Run) currentNode, e.getMatchOffset());

        // This array is used to store all nodes of the match for further removing.
        ArrayList runs = new ArrayList();

        // Find all runs that contain parts of the match string.
        int remainingLength = e.getMatch().group(0).length();
        while (
                (remainingLength > 0) &&
                        (currentNode != null) &&
                        (currentNode.getText().length() <= remainingLength)) {
            remainingLength = remainingLength - currentNode.getText().length();

            // Select the next Run node.
            // Have to loop because there could be other nodes such as BookmarkStart etc.
            do {
                currentNode = currentNode.getNextSibling();
            while ((currentNode != null) && (currentNode.getNodeType() != NodeType.RUN));

        // Split the last run that contains the match if there is any text left.
        if ((currentNode != null) && (remainingLength > 0)) {
            SplitRun((Run) currentNode, remainingLength);

        DocumentBuilder builder = new DocumentBuilder((Document) e.getMatchNode().getDocument());
        builder.moveTo((Run) runs.get(runs.size() - 1));
        builder.insertField("MERGEFIELD \"" + e.getMatch().group(0) + "\"", null);
        //Now remove all runs in the sequence.
        for (Run run : (Iterable<Run>) runs)

        return ReplaceAction.SKIP;
private static Run SplitRun(Run run, int position) throws Exception {
    Run afterRun = (Run) run.deepClone(true);
    run.setText(run.getText().substring(0, position));
    run.getParentNode().insertAfter(afterRun, run);
    return afterRun;

I hope, this helps.
Best regards,

Hi Awais!

Thanks for your answer.
I was able to create MergeFields via MS Word and I saw that aspose has identified them.
I used this to check

How can I insert values into these fields via Aspose? I have only found via getMailMerge().execute, is this right? 'Cause it isn’t MailMergeFields…


PS: I’m sending a new copy of my doc!

Hi Rafael,
Thanks for your inquiry. There are no real merge fields in your ‘Documento.odt’ document either. If there are real merge fields then yes you can use getMailMerge().execute method:
How to Execute Simple Mail Merge
However, for static place holders, as mentioned in my previous post, please convert them to real merge fields before calling getMailMerge().execute method. There is another way you can replace these place holders with new values using ‘Find and Replace’ capabilities of Aspose.Words. Please check the following article:
Find and Replace Overview
Best regards,


As I said, I was able to insert merge fields in my document (via MS Word) and use getMailMerge.execute() (even they are not actually mail merge fields, only merge fields).
But now my problem is: when I open this template in LibreOffice and save it, it loses the merge fields. They become (I think) placeholders instead.
I know it’s not what you are here for, but you know how I can actually create merge fields in a template via LibreOffice and use it with aspose? I only saw tutorial to Word in your documentation.

Another thing:
With both Execute (MailMerge) and with Replace, Aspose changes something in my document.
I will attach the template and the final document so you can see the changes:

  1. It adds “1.” and “2.” to my labels “Do” (From) and “Ao” (To);
  2. Align the text to right on values of these labels above;
  3. Compress the label “ASSINADO DIGITALMENTE” (digitally signed); and
  4. Enlarges foot syze (where there’s a field c_NUP).

Thanks a lot.

Hi Rafael,

Thanks for the additional information. Please do the following steps to insert a merge field using OpenOffice Writer:

Select Insert > Fields > Other. The Fields dialog box opens.
Click the Database tab.
On the left hand side, select Mail merge fields.
Under Database selection find your data source. Expand it to see the fields.
Click the field you want to insert, then click Insert to insert the field. You can insert any number of fields any number of times into your mail merge document.
Click Close when you are done.

After that you can use getMailMerge().execute method to perform mail merge.

Secondly, regarding the four points you mentioned, we tested the scenario and have managed to reproduce the same problems on our end. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-12024. Our product team will further look into the details of these problems and we will keep you updated on the status of correction. We apologize for your inconvenience.

Best regards,

Thanks Awais.

If possible, please send me an e-mail whenever you correct this issue.

About creating Merge Fields
MS Word gives 2 possiblities: creating just a merge field and creating a merge field from a database.
I don’t see this possibility on LibreOffice, that’s what I’ve asked.
In my case, these fields will be populated via LotusNotes script, they are not a Mail Field.



PS: I was able to identify some hidden problems with identation in the template (I simply deleted the entire line of problems 1 and 2, mentioned above, and redid the lines) and it worked well.
The problems 3 and 4, however, continues.

Here are the new examples of what I’ve said.

The field “ASSINADO DIGITALMENTE” continues without margin and the footer changed the position (up a few lines)

Hi Rafael,

Thanks for your inquiry. Unfortunately, this issue (WORDSNET-12024) is not resolved yet. Currently, this issue is pending for analysis and is in the queue. Please note that an issue first needs to be investigated to find the exact source of problem and then we investigate the best possible way to fix the issue. Once the issue is analyzed, we will then be able to provide you more information. Rest assured, we will inform you via this thread as soon as this issue is resolved. Sorry for any inconvenience.

Best regards,

Thanks, Awais.

Do you have a guess/prediction on how long it will take?
Just to know if it’s going to take long than 25 days and I won’t be able to use the trial anymore.

Hi Rafael,

Thanks for your inquiry. Unfortunately, at the moment we cannot provide you any reliable estimate. We will inform you as soon as this issue is resolved. We apologize for your inconvenience.

Best regards,

The issues you have found earlier (filed as WORDSNET-12024) have been fixed in this .NET update and this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.