Heading Counter restarts after Section Break

Hi

Im facing a strange behaviour since I’ve updated to Aspose 18.11.
My docx contains many Headings and sometimes a Heading is followed by a section break.
When I mailmerge the docx with Aspose Word the Heading counter restarts after each section break. So the whole numbering on the headings is muddled.
The same code worked with an older Versions of Aspose. (For Example Version 15.3)
I simplified the whole thing and still end up with the same issue. It’s reproducible with a very basic example, see the attachment. (Left hand side before merging)

headingProblem.png (18.0 KB)

Here is the code snippet:

Document doc = new Document(dirPath + “simpleSystembook.docx”);
String[] fieldNames = new String[1];
String[] fieldValues = new String[1];
fieldNames[0] = “bla”;
fieldValues[0] = “bla”;
doc.getMailMerge().execute(fieldNames, fieldValues);
doc.save(dirPath + “MERGEDsimpleSystembook.docx”);

The Word File is also as basic as possible. It doesn’t even contain any mergeFields.

Is this a known issue or am I missing something?

Thanks for your support
Oliver

@thomas.sauter

Thanks for your inquiry. To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document.
  • Please attach the output Word file that shows the undesired behavior.
  • Please attach the expected output Word file that shows the desired behavior.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

Hi

You find the documents atteched to this message.
The zip File contains 2 Documents:

  • sourceDoc.docx - thats the docx before merging, and since not containing any mergefields also the expected output file.
  • mergedWIthAspose.docx - the docx showing the undesired behavior.

thanks for your inquiries

exampleDocx.zip (25.5 KB)

@thomas.sauter

Thanks for sharing the detail. The latest version of Aspose.Words restarts the list number after mail merge for each section.

Please use the following code example for backward compatibility upon Mail Merge. Hope this helps you.

Document doc = new Document(MyDir + "sourceDoc.docx");
String[] fieldNames = new String[1];
String[] fieldValues = new String[1];
fieldNames[0] = "bla";
fieldValues[0] = "bla";

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

doc.getMailMerge().execute(fieldNames, fieldValues);

for (Map.Entry<List, Boolean> entry : map.entrySet()) {
    List list = entry.getKey();
    list.isRestartAtEachSection(entry.getValue());
}

doc.save(MyDir + "19.2.java.docx");

Hi

That works for me.
Thanks a lot.

@thomas.sauter

Thanks for your feedback. It is nice to hear from you that your problem has been resolved. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.