In Word API, a template with repeating items is defined as a compound type.
This section describes the Word API data-merge feature of the compound type.
A data-merge field in which a data-merge is performed multiple times is called a repeating item.
As shown in the figure below, the compound type is defined by dividing it into three parts.
It corresponds to the red frame in the figure and is the range above the breakdown part.
It is different from the header of Microsoft Word.
It corresponds to the green frame in the figure and is the range where the repeating items are defined.
It corresponds to the blue frame in the figure and is the range below the breakdown part.
It is different from the footer of Microsoft Word.
In the compound type date-merge, it is necessary to map the breakdown part (with repeating items) to other data.
In Word API, the column name of the target data is called as linking key.
A column with a unique value in the data corresponds to it.
You can use CSV and JSON format files for the merging data of the compound type.
The CSV format merging data requires two files, the main data and the sub data.
The data corresponds to the header (no repeating items) and footer (no repeating items), and is the same as the simple type.
The data corresponding to the breakdown part (with repeating items), in addition to the data-merge field of the repeating items and its data, the item (linking key) and its data to represent the correspondence with the main data are required.
The "order number" in the red frame in the figure below is the linking key.
In this example, for the main data with order number "AB0001", data-merge are performed 12 times on three repeating items.
One CSV file is required for each breakdown part for sub data.
Merging data in JSON format requires one file with a hierarchical structure.
The data corresponds to the header (no repeating items) and footer (no repeating items), and is the same as the simple type.
For the linking key specified in the various interfaces, select an item name that has a unique value in the first level of data.
In the figure below, one of the "Order_number", "Company" or "Total" corresponds to it.
The data corresponding to the breakdown part (with repeating items), and defines the "AH_DETAIL" as key and the data of the breakdown part (with repeating items) as an array.
It corresponds to the red frame in the figure below.
An example is shown below.
This is an option for the row number pattern of breakdown part, and you can specify two types of repeating methods for the breakdown part:
This is default setting of Word API, which runs a data-merge with a fixed number of rows in the breakdown part defined in the template.
If more than the number of rows of data-merge occurs, the template is repeated from the second page and after.
The option "Fixed" for each interface corresponds to it.
The number of rows changes according to the number of records in the breakdown part.
The option "Variable" for each interface corresponds to it.
This option is available when the row number pattern of the breakdown part is Fixed and the data-merge result spans across multiple pages.
The following two types of editing methods can be specified:
This is the default setting of Word API and copies the entire body area of the template file.
The option "RepeatTemplate" for each interface corresponds to it.
From the second page and after, the header part of the body area is not displayed. Rows that are not repeating items in the breakdown are displayed only on the last page.
The option "RepeatDetail" for each interface corresponds to it.
This option is available when the row number pattern of the breakdown part is Fixed and the data-merge result spans across multiple pages.
The following three types of editing methods can be specified:
This is the default setting of Word API, and you do not edit the footer part in particular.
The option "LeaveAll" for each interface corresponds to it.
Delete all footer parts other than the last page.
The option "DeleteAll" for each interface corresponds to it.
For DeleteAll, leave the data-merge field in the footer part.
The option "LeaveFld" for each interface corresponds to it.
In Word API, addition to table rows, lists can also be merged as a breakdown part (with repeating items).
The row number pattern for mixed tables and listsbullets supports only variable row number.
In Word API, you can define multiple breakdown parts as below. However, the row number pattern of the breakdown part must be common in one template file and cannot be mixed.
[Install directory]/samples/templates/Compound_type_template.zip contains the following two types of templates and sample files:
Invoice (fixed row number template)
Quotation (variable row number template)