Skip to main content

XTL Cookbook

Focused, copy-paste recipes for common reporting workflows. Each recipe is a short markdown page with a scenario, the template cells, and the expected output.

The cookbook complements two existing surfaces:

  • examples/ holds three runnable templates (renewal-report, sheet-per-region, multi-source-join) that exercise composed shapes end-to-end. Copy one as a starting point.
  • spec/language.md is the normative reference for each function and directive. Use it when a recipe doesn't cover your exact case.

Recipes here favor "the smallest template that demonstrates X" over production realism — the goal is fast lookup when you remember the shape but forget the syntax.

Recipes

#RecipeWhat you'll learn
01Getting started in 5 minutesTemplate + data → output. Substitution and __config__.
02Conditional cellsIF, IFEMPTY, comparison operators, truthiness.
03Aggregates over rowsSUM, COUNT, AVERAGE, MIN, MAX — block vs whole-source.
04One file per groupFile grouping via output_file_pattern.
05One sheet per groupSheet grouping + list-based filtering.
06Runtime inputs__inputs__ for per-run values (month, region, etc.).
07Multi-source + @join__sources__, @source, @join.
08XLOOKUPCross-source lookups.
09Sort and Top-N@sort (stable), @top, multi-key sort.
10Styling and brandingtabColor, merged cells, numFmt, TEXT().
11TEXT() formattingCurrency, dates, percentages; when to use numFmt vs TEXT().
12Empty values in depthIFEMPTY, empty-vs-zero traps, (blank), aggregates over sparse data.
13Error handling for hostsCatching XtlError, the code catalog, preview() for fail-fast.
14__config__ as a value dictionaryAuthor-defined keys, type-awareness, __config__ vs __inputs__.
15Composing directivesExecution order, multi-@filter AND, forbidden compositions.

How to read a recipe

Each recipe has the same shape:

  1. Scenario — the operator's goal in one sentence.
  2. __config__ — required keys.
  3. Template cells — the smallest set of cells that produce the goal.
  4. Data — a tiny input table.
  5. Output — what convert() returns.
  6. Notes — gotchas and pointers to the spec when you want more.

Conventions

  • Cells use the A1 notation Excel uses, not [row, col].
  • __config__ values are written as key = value for compactness; in a real template.xlsx they live in two columns (A: key, B: value).
  • Source data is shown as a markdown table to keep the recipe terse. The real data.xlsx would have those rows in a worksheet matching source_sheet.

Running a recipe

The cookbook recipes are documentation-first — not every recipe ships with a runnable .xlsx pair. To try one:

  1. Open Excel and create a new workbook.
  2. Add the __config__ sheet with the keys listed.
  3. Add the data sheet matching source_sheet.
  4. Add the template sheet with the cells from the recipe.
  5. Save as template.xlsx. Save the data as data.xlsx.
  6. Run convert(templateBuffer, dataBuffer) (see README).

Or, faster: copy one of the runnable examples and adapt it.