Table of Contents
In a WordWriter template, a merge field displays a data source field (for example, a database column name) where a data source value will be inserted. A template may include merge fields in repeat blocks, merge fields in the main document, or both. A repeat block is a text fragment, a list, or a table row in the template document, defined by a Word bookmark, that contains merge fields. The main document is any part of the template that is not within a repeat block.
WordWriter provides two methods for binding merge fields to a data source: SetDataSource and SetRepeatBlock. SetDataSource sets a data source for merge fields in the main document. SetRepeatBlock sets data sources for merge fields within repeat blocks.The main document may include multiples sets of merge fields, where each set of fields binds to a different data source. A SetDataSource call is required for each set of main document merge fields. Only one row of data can be imported to each set of main document merge fields. When you include more than one set of merge fields in the main document, use any of the following SetDataSource methods to set data sources:
The SetDataSource method is described in fuller detail on this page in our product documentation: SetDataSource.
A template can include multiple repeat blocks. Each repeat block binds to a different data source. A SetRepeatBlock call is required for each repeat block in the template. A repeat block will be repeated for each row returned from the data source.
The "Purchase Order Document" code sample generates a Word file from a template that contains a set of merge fields in the main document, and a set of merge fields within a single repeat block. The repeat block's bookmark name is "DetailRow." The code assigns two data sources to the template. setDataSource binds an array data source to the main document's merge fields, and setRepeatBlock binds a ResultSet data source to the merge fields within the "Detail Row" repeat block.