Different section between TableStart and TableEnd

Hello Aspose Support Team,


We get the following error when we try to insert different section between a TableStart and TableEnd: Mail merge region ‘SubAgreements’ is badly formed. TableStart and TableEnd should be in the same section, same table row or same table cell.

The error is pretty clear, but if we cannot have different sections, then how would can we achieve a mix between landscape portrait pages between a TableStart and a TableEnd?

Best Regards,
Morten
Hi Morten,

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

  • Your template document
  • Source code without compilation errors to reproduce the issue on our end
  • Your expected document which shows the correct output. Please create this document using Microsoft Word application.

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

PS: To attach these resources, please zip them and Click 'Reply' button that will bring you to the 'reply page' and there at the bottom you can include any attachments with that post by clicking the 'Add/Update' button.

Best regards,

Is an example really necessary? the exception I see is explanatory enough.


What I am looking for, is for you to explain how to make a mix a landscape and portrait pages between a table start and table end ( in mail merge )

Hi Morten,


Thanks for your inquiry. Well, it is by design that the TableStart and TableEnd fields must be inside the same section in your document. After the mail merge, you may want to manipulate document further and specify PageSetup.Orientation values for each section.

If we can help you with anything else, please feel free to ask.

Best regards,
We cannot manipulate the document further after the mail merge has taken place.

The reason for this is that in our system, documents with merge fields are uploaded by users and these are paired with "data providers" (IMailMergeDataSource) - documents are therefore not "known" to us up front and therefore we cannot manipulate the document further after the mail merge has taken place..

Hi Morten,


Thanks for your inquiry. When executing MailMerge.ExecuteWithRegions method, I think, it is best that you please educate your users about the following points/rules:

  • Every table in the DataSet must have a name.
  • The document must have mail merge regions defined with names that refer to the tables in the DataSet.
  • To specify a mail merge region in the document you need to insert two mail merge fields to mark beginning and end of the mail merge region.
  • All document content that is included inside a mail merge region will be automatically repeated for every record in the DataTable.
  • To mark beginning of a mail merge region insert a MERGEFIELD with name TableStart:MyTable, where MyTable corresponds to one of the table names in your DataSet.
  • To mark the end of the mail merge region insert another MERGEFIELD with name TableEnd:MyTable.
  • To insert a MERGEFIELD in Word use Insert/Field command and select MergeField then type the name of the field.
  • The TableStart and TableEnd fields must be inside the same section in your document.
  • If used inside a table, TableStart and TableEnd must be inside the same row in the table.
  • Mail merge regions in a document should be well formed (there always needs to be a pair of matching TableStart and TableEnd merge fields with the same table name).
  • Mail merge regions can be nested inside each other.
  • Duplicate regions with the same name are allowed. However successfully merging duplicated regions depends on the type of data source being used for mail merge:

Hope, this helps.

Best regards,