# Excel template filler API

> Fill an Excel .xlsx template with {placeholders} and repeated rows from JSON, keeping styles, formulas, merges and print setup; batch to a ZIP.

- Endpoint: `POST https://apibox.io.vn/v1/xlsx-template`
- Category: Files
- HTML docs: https://apibox.io.vn/docs/xlsx-template/ (Vietnamese: https://apibox.io.vn/vi/docs/xlsx-template/)
- Online tool: https://apibox.io.vn/tools/xlsx-template/
- Authentication: `Authorization: Bearer <API key>` or `X-API-Key: <API key>` (free key: https://apibox.io.vn/dashboard/#signup)

Upload your own .xlsx (the form your accountant or a government agency requires) with placeholders in cells and send the data as JSON. `{so_hd}` or `{{so_hd}}` inserts a value (dotted paths like `{khach.ten}` work, in any sheet); a cell that holds only a placeholder gets a real number, boolean or date (when the cell has a date format), so number formats such as `#,##0 ₫` still apply. Filters: `{tong|words}` (amount in Vietnamese words), `|money`, `|date` (dd/mm/yyyy), `|date_vi`, `|excel_date`, `|upper`, `|lower`, `|join`, `|default:…`.

A row that refers to an array (`{items.ten}`, `{items.sl}`, with `{$index}` for the line number) is repeated for each element. The engine edits the workbook XML directly, so cell styles, column widths, other sheets, images and print settings are untouched, and rows below move down: formulas are shifted (`=SUM(E6:E6)` becomes `=SUM(E6:E8)`, `=C6*D6` follows each copy), merged cells, conditional formatting, data validation, print areas and references from other sheets are updated, and Excel recalculates on open.

Send `rows` (an array) instead of `data` to produce one workbook per object in a ZIP, named with `filename` such as `BG_{so}`. `action=tags` lists the placeholders. Old .xls files, macros (.xlsm), pivot tables and Excel tables (ListObjects) over repeated rows are not adjusted. Files are processed in memory and not stored.

## Parameters

| Name | In | Type | Required | Default | Description |
|---|---|---|---|---|---|
| `template` | body | file | yes |  | The .xlsx template (multipart `template` or `file`, or `template_base64`). |
| `data` | body | object | no |  | Values for one workbook (JSON object). |
| `rows` | body | array | no |  | Batch: one workbook per object, returns a ZIP (max 500). |
| `filename` | body | string | no | `workbook` | Output name, with placeholders: `BG_{so}`. |
| `output` | body|query | string | no | `xlsx` | `xlsx` (file) or `json` (tags, missing fields, base64). |
| `action` | body|query | string | no |  | `tags`: list the placeholders only. |

## Example request

```bash
curl -X POST "https://apibox.io.vn/v1/xlsx-template" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -F "0=@./my-file"
```

## Example response

```json
{
  "filename": "workbook.xlsx",
  "sheets": [
    "Bao_gia",
    "Ky"
  ],
  "tags": [
    {
      "name": "so",
      "cells": [
        "Bao_gia!A1"
      ]
    },
    {
      "name": "khach.ten",
      "cells": [
        "Bao_gia!A2"
      ]
    },
    {
      "name": "ngay",
      "cells": [
        "Bao_gia!B3"
      ]
    },
    {
      "name": "$index",
      "cells": [
        "Bao_gia!A6"
      ]
    },
    {
      "name": "items.ten",
      "cells": [
        "Bao_gia!B6"
      ]
    },
    {
      "name": "items.sl",
      "cells": [
        "Bao_gia!C6"
      ]
    },
    {
      "name": "items.gia",
      "cells": [
        "Bao_gia!D6"
      ]
    },
    {
      "name": "tong|words",
      "cells": [
        "Bao_gia!A8"
      ]
    },
    {
      "name": "ghi_chu",
      "cells": [
        "Bao_gia!A9"
      ]
    },
    {
      "name": "nguoi_lap",
      "cells": [
        "Ky!A1"
      ]
    }
  ],
  "repeated_rows": 1,
  "missing_fields": [
    "ghi_chu",
    "nguoi_lap"
  ],
  "xlsx_base64": "UEsDBBQAAAgIAAAAAACI4g+7GgEAALcDAAATAAAAW0NvbnRlbnRfVHlwZXNd…",
  "bytes": 3543
}
```

## Use cases

- Fill quotation, invoice or delivery templates with line items
- Produce tax and insurance declaration forms that must keep the official layout
- Mail-merge payslips or certificates into a ZIP of workbooks
- Generate periodic reports from Google Sheets / n8n data into a fixed template

## FAQ

### Do my formulas still work after rows are inserted?

Yes. References below the repeated rows are shifted, ranges that cover the template row grow with it, and the workbook is set to recalculate when opened.

### Can a placeholder be part of a longer text?

Yes: "Khách hàng: {khach.ten}" becomes a text cell. A cell containing only a placeholder keeps the value type (number, date, boolean).

### What if an array is empty?

The template row is kept once with blank cells, so totals and formulas over it stay valid.
