> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lerian.studio/llms.txt
> Use this file to discover all available pages before exploring further.

# XLSX template

> Build a spreadsheet report with Reporter: a template that declares a workbook of sheets, rows and typed cells, which Reporter converts into an xlsx file.

> [!WARNING]
>
> This capability is under development. It is available in homologation on Lerian Cloud, and its behavior can change before release. Confirm availability with Lerian before integration.

This page shows how to create an operations report as an `.xlsx` spreadsheet with Reporter. You write a text template that declares the workbook. Reporter renders the text, then converts it into the spreadsheet file.

Reporter converts only custom reports to xlsx. Regulatory filings are generated another way and are not converted.

## Declare the workbook

***

A template with output format `xlsx` is a `.tpl` text file like every other format. Its rendered text must be a declared workbook. The declaration uses four elements, nested in this order:

1. `workbook`: the root. A template has one.
2. `sheet`: one sheet of the file. A workbook holds one or more.
3. `row`: one row of a sheet.
4. `cell`: one cell of a row. A cell holds text only.

Each element takes only the attributes in this table.

| Element | Attributes |
| - | - |
| `workbook` | None |
| `sheet` | `name` |
| `row` | None |
| `cell` | `type`: `text`, `number` or `date` |

Reporter refuses a rendered text that breaks these rules:

* Any other element, attribute or namespace.
* A repeated attribute.
* Text outside a cell. Only white space may stand between elements.
* A `type` value that is not `text`, `number` or `date`. The value is case-sensitive.
* A processing instruction or a DOCTYPE. An XML declaration is accepted only at the start of the text, with version 1.0 and UTF-8.

Comments are ignored. A cell without `type` is a text cell.

When you create or update an xlsx template, Reporter checks that the text holds `<workbook`. If it does not, Reporter answers `400 RPT-0007`.

A template cannot declare these items. Every cell uses one Calibri 11 font.

* Column widths
* Styles and fonts
* Formulas
* Merged cells
* Hidden sheets

The [template builder](https://docs.lerian.studio/en/products/reporter/console/template-builder.md) wraps the generated body in `<workbook>` when the format is `xlsx`. It offers no sheet, row or cell block, so you write those in the template code.

### Template code

This template loops over the operations of a ledger. It writes one sheet named `Operations`. The first row is a header. Each operation adds one row of typed cells.

```xml XML expandable theme={null}
<workbook>
  <sheet name="Operations">
    <row>
      <cell>Operation ID</cell>
      <cell>Account alias</cell>
      <cell>Type</cell>
      <cell>Amount</cell>
      <cell>Asset</cell>
      <cell>Description</cell>
      <cell>Generated on</cell>
    </row>
    {%- for operation in midaz_transaction.operation %}
    <row>
      <cell>{{ operation.id }}</cell>
      <cell>{{ operation.account_alias }}</cell>
      <cell>{{ operation.type }}</cell>
      <cell type="number">{{ operation.amount|decimal:2 }}</cell>
      <cell>{{ operation.asset_code }}</cell>
      <cell>{{ operation.description }}</cell>
      <cell type="date">{% date_time "YYYY-MM-dd" %}</cell>
    </row>
    {%- endfor %}
  </sheet>
</workbook>
```

### Code breakdown

**`<sheet name="Operations">`**

Starts the only sheet of the workbook.

**`<row>` with `<cell>` header text**

The first row has seven text cells.

**`{%- for operation in midaz_transaction.operation %}`**

Runs the row block once for each operation. Each pass writes one row.

**`<cell type="number">{{ operation.amount|decimal:2 }}</cell>`**

Writes the amount as a number with two decimal places. The `decimal` filter keeps the trailing zeros. It also rounds to the number of places you give. Use the largest scale among the assets the report reads, up to 15 places. See [Cell types](#cell-types).

**`<cell type="date">{% date_time "YYYY-MM-dd" %}</cell>`**

Writes the generation date in the time zone of the server, such as `2026-11-24`. In the `date_time` format the day is `dd`. `DD` prints as literal text, and the date cell refuses it.

To write a date from your data, format it with the `date` filter. Reporter refuses a raw timestamp in a date cell.

```django theme={null}
<cell type="date">{{ operation.created_at|date:"2006-01-02" }}</cell>
```

Reporter escapes the values a template prints. A `&` or `<` in your data reaches the cell as the original character. Text you write in the template itself is XML. Write `&amp;` and `&lt;` there.

### Template output

The template preview answers the declared workbook as XML. The report is the spreadsheet file, with the same cells.

```xml XML expandable theme={null}
<workbook>
  <sheet name="Operations">
    <row>
      <cell>Operation ID</cell>
      <cell>Account alias</cell>
      <cell>Type</cell>
      <cell>Amount</cell>
      <cell>Asset</cell>
      <cell>Description</cell>
      <cell>Generated on</cell>
    </row>
    <row>
      <cell>01965f04-7087-73f1-a802-f8fceedb34ec</cell>
      <cell>@external/BRL</cell>
      <cell>DEBIT</cell>
      <cell type="number">1500.00</cell>
      <cell>BRL</cell>
      <cell>Initial transfer</cell>
      <cell type="date">2026-11-24</cell>
    </row>
  </sheet>
</workbook>
```

## Cell types

***

A cell has one of three types. Integers and decimals are both `number`. A template cannot declare boolean, datetime or error cells.

| Type | How you write it | How Reporter stores it |
| - | - | - |
| `text` | Any characters. This is the default. | As text |
| `number` | `-`, digits, and optionally `.` and digits | As a numeric value |
| `date` | `YYYY-MM-DD` | As a date, with the built-in short-date format |

### Text cells

A text cell keeps every character between its tags. Surrounding white space and line breaks stay. A raw CR or CRLF becomes LF.

A text cell that starts with `=` stays text. Reporter never stores it as a formula.

### The trailing-zero trap

Before the conversion, Reporter removes trailing zeros from numbers in the whole rendered text. This includes text cells. The value `1.500` is written as `1.5`.

To keep the zeros, print the value with the `decimal` filter and a number of places:

```django theme={null}
<cell type="number">{{ operation.amount|decimal:3 }}</cell>
```

This prints `1.500`. The filter rounds to the places you give. In a number cell, use at most 15 places: 16 or more fails the report, even for `1.5`.

### Number cells

A number has an optional `-`, then digits, and optionally `.` followed by digits. Reporter refuses these forms:

* A leading `+`
* An exponent
* A group separator
* `.5` and `5.`

A number has at most 15 significant digits and at most 15 digits after the point. Reporter refuses a longer number. It never rounds it.

A number with n digits after the point shows exactly n decimals. An integer uses the General format.

### Date cells

A date is exactly `YYYY-MM-DD`, from 1900-03-01 to 9999-12-31. A date carries no time.

### Empty cells

A number or date cell is trimmed of surrounding space, tab, CR and LF. A cell that is empty after the trim writes nothing. The cell keeps its column, so columns are positional.

## Limits

***

None of these limits is configurable.

| Limit | Value |
| - | - |
| Rows per sheet | 1,048,576 |
| Cells per row, empty cells included | 16,384 |
| Characters per text cell | 32,767 |
| Sheet name | 1 to 31 characters |
| Number | 15 significant digits, 15 after the point |
| Uncompressed XML of one sheet | Under 4 GiB |
| Sheets | At least 1, no maximum |

A character outside the basic plane, such as an emoji, counts as two. A sheet name must meet these rules:

* It has no control character.
* It has none of `/ \ ? * : [ ]`.
* It does not start or end with an apostrophe.
* It is not `History`, in any letter case.
* It holds no literal `_xHHHH_`.
* It does not repeat the name of another sheet, in any letter case.

Sheets appear in the declared order. Rows are numbered one after another, and an empty `<row/>` counts as a row.

## Failures

***

A refused conversion ends the report in `Error`. Reporter stores no file and does not retry the report. The report metadata records `error`, `error_code` and `error_title`.

| Code | Message | Reason |
| - | - | - |
| `RPT-0252` | The rendered template is not well-formed XML or is not a declared workbook: a workbook holds sheet elements, a sheet holds row elements and a row holds cell elements, with no other element or attribute and no text outside a cell. See the rendered text at line N. | The text breaks the declaration rules. |
| `RPT-0253` | A workbook value does not fit: the reason (sheet S, row R, column C). Correct the template or the data and generate the report again. | A value or shape does not fit the workbook. |

`RPT-0252` also covers invalid UTF-8 and any character that XML 1.0 forbids.

`RPT-0253` gives one of four reasons:

1. The value does not fit its cell type.
2. The sheet name is refused.
3. A workbook limit is reached.
4. The workbook has no sheet.

Positions in `RPT-0253` start at 1. Some positions are 0:

* A refused sheet name has row 0 and column 0.
* An empty workbook has sheet 0, row 0 and column 0.
* The row limit and the 4 GiB limit have column 0.

Neither message carries a cell value or a sheet name. Conversion stops at the first refusal.

### Preview

The template preview answers the rendered declared workbook as `application/xml`, not as a spreadsheet. It also runs the conversion. If the conversion is refused, the preview answers `400` with `RPT-0252` or `RPT-0253`.

The preview renders up to 5 MiB. If it cuts the output at that size, it warns "Output truncated at 5 MiB; the rendered document is larger." and skips the conversion check.

### In the Console

The template builder preview says "The preview shows the declared workbook; the report is the spreadsheet".

An xlsx report has no on-screen preview. The report preview says "This report is a spreadsheet and has no preview. Download it to open it."

Only a finished report downloads. Other states answer `422 RPT-0029`. The API download answers the media type `application/vnd.openxmlformats-officedocument.spreadsheetml.sheet` with the file name `<reportId>.xlsx`.

The Console names the downloaded file after the template. It uses lowercase letters and underscores for spaces. It adds the UTC date of the download: `<template>_<yyyy-mm-dd>.xlsx`.

## Next steps

***

> [card] [Template reference](https://docs.lerian.studio/en/products/reporter/template-reference.md)
>
> Every tag and filter, including `decimal`.

> [card] [Template engine](https://docs.lerian.studio/en/products/reporter/reporter-template-engine.md)
>
> How Reporter renders a template.

> [card] [Template examples](https://docs.lerian.studio/en/products/reporter/template-examples.md)
>
> Worked templates for the other output formats.

> [card] [Download a report](https://docs.lerian.studio/en/products/reporter/console/downloading-a-report.md)
>
> Download the finished spreadsheet from the Console.

> [card] [File datasets](https://docs.lerian.studio/en/products/reporter/file-datasets.md)
>
> Read delivered files as data for your reports.

> [card] [Read an xlsx file as a dataset day](https://docs.lerian.studio/en/products/reporter/file-dataset-contract.md#xlsx)
>
> The opposite direction: xlsx as input.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.