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

Free Support Forum - aspose.com

Bug with Office 2016 MailMerge and USE_DESTINATION_STYLES

Hi Support Team,

I am working on a application now which is merging document.
If I am using “USE_DESTINATION_STYLES” to merge my documents, then the header layout + TOC looks exactly how it should looks like as I can configure them in my first documet.

But if I merge documents + “USE_DESTINATION_STYLES” + the getMailMerge().execute method, then the layout is getting broken.
If I just remote getMailMerge, then the layout is perfect, but of course my metadata is not replaced.

I have uploaded the documents + source codes, just review the layout with numeric headers and TOC numbers. You will see that “LayoutNOToK” always have 1 as chapter number, even the document has 4 chapters.

“LayoutOK” works fine, but metadata is not replaced.

Any idea how I can fix it?

Btw, even also interesting:
The Layout looks ok on Office 2013 b ut looks wrong in Office 2016

I need the layout on Office 2016 with mailMerge.
Your help is appriciated.

office2013 vs office2016.png (28.8 KB)

Layout_Bug.zip (506.7 KB)

@kai20511,

Thanks for your inquiry. Please use List.IsRestartAtEachSection property as shown below to get the desired output. Moreover, we suggest you please use OoxmlCompliance as shown in example.

Document content = new Document(MyDir + "Cover.docx");
Document b1 = new Document(MyDir + "Book.docx");
Document b2 = new Document(MyDir + "Book_Action.docx");
Document m1 = new Document(MyDir + "Movies.docx");
Document m2 = new Document(MyDir + "Movies_Action.docx");

content.getFirstSection().getPageSetup().setSectionStart(SectionStart.CONTINUOUS);
content.appendDocument(b1, ImportFormatMode.USE_DESTINATION_STYLES);
content.getFirstSection().getPageSetup().setSectionStart(SectionStart.CONTINUOUS);
content.appendDocument(b2, ImportFormatMode.USE_DESTINATION_STYLES);
content.getFirstSection().getPageSetup().setSectionStart(SectionStart.CONTINUOUS);
content.appendDocument(m1, ImportFormatMode.USE_DESTINATION_STYLES);
content.getFirstSection().getPageSetup().setSectionStart(SectionStart.CONTINUOUS);
content.appendDocument(m2, ImportFormatMode.USE_DESTINATION_STYLES);

String[] var = { "name", "address" };
String[] result = { "kai", "home" };

content.getMailMerge().execute(var, result);

for(List list : content.getLists())
{
    list.isRestartAtEachSection(false);
}
content.updateFields();
content.updatePageLayout();
content.updateListLabels();

OoxmlSaveOptions options = new OoxmlSaveOptions();
options.setCompliance(OoxmlCompliance.ISO_29500_2008_TRANSITIONAL);
content.save(MyDir + "18.7.docx", options);

@tahir.manzoor
Many thanks. Thats working!

Let me please ask two more questions.
Can you explain why it works on Word 2013 ? This question has no priority, I am just interested to get more background about it.

Second, is it prefered to use OoxmlSaveOptions ?
I am asking as I have not seen this in any example source before.

Again, many thanks for this great and quick support.

@kai20511,

Thanks for your inquiry.

Please note that MS Word and Aspose.Words apply restartNumberingAfterBreak attribute for each list in document during mail merge. We will check it with MS Word 2013 and share our findings with you.

The OoxmlSaveOptions class can be used to specify additional options when saving a document. In your case, there is no need to use this class.

We have tested the scenario and have noticed that List.IsRestartAtEachSection does not work when DOCX is opened in MS Word 2013. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-17267. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

@tahir.manzoor
Many thanks. Really appriciated.

@kai20511,

Thanks for your patience. Regarding WORDSNET-17267, we have checked this issue at different system with MS Word 2013. It seems that it is a bug in MS Word 2013. Could you please upgrade to the latest version of MS Word 2013 and check this issue? Please share your findings here for our reference.

If you still face problem, please share your expected output Word document generated by MS Word 2013. Thanks for your cooperation.

@tahir.manzoor
Many thanks for following this issue.
I have upgraded to Office 2016 now and all problems are gone.

Also by using “list.isRestartAtEachSection(false);” worked with office 2013as well so all fine by now.

Many thanks

@kai20511,

Thanks for your feedback. We have closed this issue WORDSNET-17267. Please let us know if you have any more queries.