Exception - Mail merge region is badly formed

Hello there,

I am getting following exception while trying to run Mail.Merge.ExecuteWithRegions:
Mail merge region ‘Template’ is badly formed. TableStart and TableEnd should be in the same section, same table row or same table cell.

I have attached source document for your reference.
Could you please guide what is wrong with my document.
Thank you!

Hello

Thanks for your request. Please see the following link to learn how to work with TableStart/TableEnd construction:
https://docs.aspose.com/words/java/types-of-mail-merge-operations/
Follow these simple rules when marking a region:

  • TableStart and TableEnd fields must be inside the same section in the document.
  • If used inside a table, TableStart and TableEnd must be inside the same row in the table.
  • Mail merge regions can be nested inside each other.
  • Mail merge regions should be well formed (there is always a pair of matching TableStart and TableEnd with the same table name).

In your case I think it should be enough just removing Section Break between TableStart:Template and TableEnd:Template.
Please let me know if you need any further assistance. I will be glad to help you.
Best regards,

Hello Andrey,

Thanks for your reply.

Can please explain what do you mean by ‘same section’?
Also, how can I remove section break between TableStart:Template and TableEnd:Template?

Hello

Thanks for your inquiry. A Word document can contain one or more sections. At the end of the section, there is a section break that separates one section from the next in a document. Each section has its own set of properties that specify page size, orientation, margins, the number of text columns, headers and footers and so on.
https://docs.aspose.com/words/net/working-with-sections/
Please see the attached screenshot to see Section Break. You should just remove this Section Break.
Best regards,