aspose-words / Aspose.Words-for-Java

Aspose.Words for Java examples, plugins and showcases
https://products.aspose.com/words/java
MIT License
401 stars 206 forks source link

UpdateFields BUG #66

Closed Deathef closed 4 years ago

Deathef commented 4 years ago

I call the method getMailMerge().execute() after updateFields, then it comes a bug like this demo1 demo2

        String resourceWordPath = "demo.docx";
        String targetWordPath = "demo1.docx";
        try {
            WordToPdfUtils.getLicense();
            Document doc = new Document(resourceWordPath);
            doc.getMailMerge().execute(new String[]{"name"}, new String[]{"111"});
            doc.updateFields();
            doc.save(targetWordPath);
        } catch (Exception e) {
            e.printStackTrace();
        }
AlexNosk commented 4 years ago

@Deathef Could you please attach the source template, the output document and the desired output? We will check the issue and provide you more information.

Deathef commented 4 years ago

@AlexNosk annex is the source template, the output document and the desired output demo.zip

AlexNosk commented 4 years ago

@Deathef Thank you for additional information. I managed to reproduce the problem on my side and logged the issue as WORDSNET-20778 in our bug traching system We will let you know once the issue is resolved.

AlexNosk commented 4 years ago

@Deathef MS Word applies restartNumberingAfterBreak attribute to each list in document during mail merge. Aspose.Words also follows this behavior. So this is considered as Not a bug. You may use the following code snippet to retain original list numbering:

Document doc = new Document(resourceWordPath);

Map<List,Boolean> lists = new HashMap<List,Boolean> ();
for (List list : doc.getLists())
    lists.put(list,list.isRestartAtEachSection());

doc.getMailMerge().execute(new String[]{"name"}, new String[]{"111"});

for (Map.Entry<List, Boolean> pair : lists.entrySet())
    pair.getKey().isRestartAtEachSection(pair.getValue());

doc.updateFields();
doc.save(targetWordPath);

Please let me know if the proposed workaround works for you and the issue can be closed.

Deathef commented 4 years ago

@AlexNosk According to the code you provided, we successfully solved the problem;