Compound type data-merge

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.

Repeating item

A data-merge field in which a data-merge is performed multiple times is called a repeating item.

Definitions in compound type

As shown in the figure below, the compound type is defined by dividing it into three parts.

Compound Part Image

Header (no repeating items)

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.

Breakdown part (with repeating items)

It corresponds to the green frame in the figure and is the range where the repeating items are defined.

Footer (no repeating items)

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.

linking key

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.

Merging data

You can use CSV and JSON format files for the merging data of the compound type.

Merging data (CSV)

The CSV format merging data requires two files, the main data and the sub data.

Main data

The data corresponds to the header (no repeating items) and footer (no repeating items), and is the same as the simple type.

Sub data

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.

Compound CsvData Image

Merging data (JSON)

Merging data in JSON format requires one file with a hierarchical structure.

First layer

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.

Second layer

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.

Compound JsonData Image

Example of compound type data-merge

An example is shown below.

Compound data merge exec example Image

Options

Row number pattern of breakdown part

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:

Fixed row number (default)

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.

Compound Fix Image

Variable row number

The number of rows changes according to the number of records in the breakdown part.
The option "Variable" for each interface corresponds to it.

Compound Variable Image

Style when a breakdown part with a fixed number of rows spans multiple pages

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:

Copy the entire body area (default)

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.

Repeating the breakdown part

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.

Compound Fix RepeatDetail Image

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.

Compound Fix DeleteAll Image

For DeleteAll, leave the data-merge field in the footer part.
The option "LeaveFld" for each interface corresponds to it.

Compound Fix LeaveFld Image

Types of breakdown part

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.

Compound Bullet Image

Number of breakdown part

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.

Example when there are multiple tables

Compound Multi Table Image

Example when there are multiple lists

Compound Multi Bullet Image

Sample files

[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)