Looped Data Items

Generating Documents with Line Items (Repeating Rows)

Use this feature when each document needs a table that repeats for every row of related data — invoices with line items, order confirmations with products, reports with entries, certificates with competencies, and so on.


How it works

You provide two things:

  1. A Word template with a special table row using {{item.ColumnName}} placeholders. Sample.
  2. An Excel file with two sheets — one sheet for the main data (one row per document) and one sheet for the line items (multiple rows per document). Google Sheets can be setup in the same way. Sample.

ActiveMerge automatically links them together and generates one document per main-data row, with the line-items table expanded to include all the related rows.

DON’T USE SPACES OR / FORWARD SLASH OR OTHER SYMBOLS IN YOUR HEADERS. Replaces spaces with underscors _ like Your_Item.


Step 1 — Set up your Excel file

Your Excel file needs two sheets.

Sheet 1 — Main data

One row per document. This works exactly like a normal mail merge.

InvoiceNo Client Date Total
INV-001 Acme Corp 2026-05-09 $1510.00
INV-002 Globex Ltd 2026-05-10 $600.00

Sheet 2 — Line items

Multiple rows per document, with a join column that matches a column name in Sheet 1.

InvoiceNo Description Qty Unit Price
INV-001 Web Design 1 $1500.00
INV-001 Domain Name 1 $10.00
INV-002 Consulting 3 $200.00

The join column (InvoiceNo in this example) is the column that appears in both sheets. ActiveMerge detects it automatically — you don’t need to configure anything. Just make sure the column name is spelled the same in both sheets.

Rules for Sheet 2

  • The first row must be a header row with column names
  • Column names with spaces will have their spaces replaced with underscores in the template (e.g. Unit PriceUnit_Price)
  • Rows with no join key value are ignored
  • A document with no matching line items will generate with an empty table (the template row disappears)

Step 2 — Set up your Word template

In your .docx template, create a table with a header row and one data row.

In the data row, use {{item.ColumnName}} placeholders — where ColumnName matches the column headers in Sheet 2.

Example invoice table:

Description Qty Unit Price
{{item.Description}} {{item.Qty}} {{item.Unit_Price}}

Important: Use double curly braces {{ }} for line item placeholders, not single braces { }. Your regular main-data placeholders (like {InvoiceNo} and {Client}) continue to use single braces as normal.

The data row repeats automatically for each matching line item. You do not need to add any loop tags or special formatting — ActiveMerge handles this for you.

Full template example

Invoice Number: {InvoiceNo}
Client: {Client}
Date: {Date}

+---------------------+-----+------------+
| Description         | Qty | Unit Price |
+---------------------+-----+------------+
| {{item.Description}}|{{item.Qty}}|{{item.Unit_Price}}|
+---------------------+-----+------------+

Total: {Total}

Step 3 — Generate your documents

Upload your template and your two-sheet Excel file exactly as you normally would. No extra steps are needed. ActiveMerge detects the second sheet automatically.


Column name reference

Sheet 2 column name Placeholder to use in template
Description {{item.Description}}
Unit Price {{item.Unit_Price}}
Product Name {{item.Product_Name}}
SKU123 {{item.SKU123}}

Rule: Spaces and hyphens in column names become underscores. Numbers and letters stay as-is.


Common use cases

Document type Main sheet columns Line items sheet columns
Invoice InvoiceNo, Client, Date, Total InvoiceNo, Description, Qty, Price
Order confirmation OrderID, Customer, ShippingAddress OrderID, Product, Quantity, SKU
Payslip EmployeeID, Name, Month EmployeeID, Earnings Type, Amount
Course certificate StudentID, Name, Course StudentID, Competency, Result
Quote QuoteNo, ProspectName QuoteNo, Item, Description, Price

Using line items via the API

If you generate documents through the ActiveMerge API, pass items as an array of objects alongside your data payload:

{
  "template_id": "your-template-id",
  "format": "pdf",
  "data": {
    "InvoiceNo": "INV-001",
    "Client": "Acme Corp",
    "Date": "2026-05-09",
    "Total": "$1510.00"
  },
  "items": [
    { "Description": "Web Design",  "Qty": "1", "Unit_Price": "$1500.00" },
    { "Description": "Domain Name", "Qty": "1", "Unit_Price": "$10.00"   }
  ]
}
  • items is optional. If omitted, the API works exactly as before.
  • Object keys in items must match the column names you used in the template (after replacing spaces with underscores).
  • items can also be sent as a JSON-encoded string for integrations like Zapier or Make that cannot send nested arrays natively.

Tips

  • Only one line-items table per template is supported. If your template has multiple tables, the first table containing {{item.*}} placeholders will be used as the loop table.
  • The header row is never repeated. Only the one data row with {{item.*}} placeholders repeats.
  • Regular placeholders still work in the same template. Mix {Client} (from Sheet 1) and {{item.Description}} (from Sheet 2) freely.
  • Preview in Step 3 uses the first document’s line items to show you how the output looks.
  • The join column can have any name — it just needs to appear in both sheets with the same spelling. Matching is not case-sensitive.

Troubleshooting

The line items table is empty or missing in my output

  • Check that your Sheet 2 join column values exactly match the Sheet 1 values (e.g. INV-001 in both sheets — not INV001 in one and INV-001 in the other).
  • Make sure the data row in your Word template contains {{item. placeholders with double curly braces.

Spaces in column names aren’t working

  • Replace spaces with underscores in your template placeholder. A column called Unit Price becomes {{item.Unit_Price}}.

All documents have the same line items

  • The join column values in Sheet 2 must vary per invoice. If all rows in Sheet 2 use the same join value, all documents will pull the same items.

I get a “No data found” error

  • Make sure Sheet 1 (the main data) is the first tab in your Excel file, and Sheet 2 (line items) is the second tab.