If you want to dynamically grow portions inside the document, use mail merge with regions. To specify a mail merge region in the document you need to insert two mail merge fields to mark the beginning and end of the mail merge region. All document content that is included inside a mail merge region automatically will be repeated for every record in the data source (in most cases this is a table).
To mark the beginning of a mail merge region, insert a MERGEFIELD with the name TableStart:MyTable, where MyTable corresponds to the name of the table. To mark the end of the mail merge region insert another MERGEFIELD with the name TableEnd:MyTable. Between these marking fields, place merge fields that correspond to the fields of your data source (table columns). These merge fields will be populated with data from the first row of the data source, then the whole region will be repeated, and the new fields will be populated with data from the second row, and so on.
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).
· 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:
o If an IMailMergeDataSource data source or a DataSet is used then duplicate regions will be merged automatically. This is due to the “root” structure of these data source types. Each region in the document is passed to these data sources and merged regardless of whether they are duplicates or not.
o If mail merge is performed using any other type of data source, for instance a DataTable then the mail merge process must be executed again to merge each duplicate region. This is because these data source types only merge the first instance of a region in a document. The mail merge process stops after the first region is merged.
As an example, have a look at the Product Catalog demo. Here is a fragment of a region prepared for mail merge:
You can see a mail merge region defined for populating with data from the Products table. Note that both the marking fields TableStart:Products and TableEnd:Products are placed inside the same row of the Word table.
After executing the mail merge, here is the result: