Skip to Content
Fetlar
Using Fetlar

Templates

Fill a Word or Excel file that has {{placeholders}} in it. Letters, invoices, certificates and reports keep their own design.

A template is an ordinary Word or Excel file with {{placeholders}} typed where the data goes. fetlar fill replaces them. Styles, headers, numbering and page setup stay exactly as the template has them.

fetlar fill letter.docx data.json -o out.docx
fetlar fill report.xlsx data.json -o out.xlsx
fetlar fill letter.docx --names

Example

A Word letter that contains:

Dear {{name}},

Your invoice total is {{total | number:"#,##0.00"}} due {{due | date:"d mmmm yyyy"}}.

and a data file:

{"name": "Sara", "total": 1250.5, "due": "2026-12-15", "items": ["Paper", "Ink"]}
fetlar fill letter.docx d.json -o out-letter.docx
fetlar out-letter.docx
Dear Sara,

Your invoice total is 1,250.50 due 15 December 2026.

To see which names a template reads from the data:

fetlar fill letter.docx --names
due
items
name
total

Mail merge

Make one file for each person with --each:

fetlar fill letter.docx people.json --each people --name "{id}-{name}" -o letters/
1-Sara.docx
2-Omar.docx

--each people takes the people list from the data. --name builds each file name from the item's fields. The default name is {index}, starting at 1. All files are written to a hidden folder first and moved into place only when every one succeeded. A file that already exists is not replaced unless you add --overwrite.

The syntax

WriteIt does
{{name}} {{customer.address.city}} {{items.0.name}}a value. Names may be Arabic
{{.}} {{$.company}}the current loop item. The data itself
{{@index}} {{@number}} {{@first}} {{@last}} {{@count}}inside a loop: position (from 0 and from 1), first, last, how many
{{@today}}the date given with --today. Today by default
{{#items}} ... {{/items}}repeat. An empty list repeats nothing. {{else}} shows something instead
{{?paid}} ... {{else}} ... {{/paid}}show if the value is true (not null, false, 0 or empty)
{{^paid}} ... {{/paid}}the opposite
{{?total > 1000}} {{?status == "open"}}one comparison: == != > >= < <=
{{amount | number:"#,##0.00"}}a formatter. Chain them left to right
{{%logo | width:"4cm"}}a picture (Word). Takes width, height, alt
{{! note }}a comment. It is removed
\{{a literal {{

Formatters

FormatterExample
number:"fmt"any Excel number format: #,##0.00, 0.0%
date:"fmt" and date:"fmt":"ar"dd/mm/yyyy, d mmmm yyyy. ar for Arabic month names
hijri:"fmt" and hijri:"fmt":"en"d mmmm yyyy gives 12 رمضان 1447
digits:"arabic"also persian and latin
upper, lower, trimchange the text
default:"-"a value to use when there is none
join:", "join a list
yesno:"yes":"no"text for true and false
countthe length of a list

A date is YYYY-MM-DD or YYYY-MM-DDTHH:MM:SS text, or an Excel serial number. Curly quotes are accepted, because Word turns " into them as you type.

Word templates

  • Placeholders work in the body, tables (also nested), headers, footers, footnotes, endnotes and text boxes.
  • Word may split a placeholder over several pieces of text. Fetlar finds it anyway. The value takes the formatting of the first piece.
  • To repeat paragraphs, put {{#items}} and {{/items}} in paragraphs of their own. Those two paragraphs disappear.
  • To repeat a table row, put the two tags in cells of that row.
  • Right-to-left settings stay as the template has them. An Arabic value put into Latin text gets Arabic bold, italic and size.
  • A .dotx template, or a .docm without macros, is filled into an ordinary document. Files that can run macros are refused.

Excel templates

  • Placeholders work in cells.
  • A cell that is only {{value}} gets a real value: a JSON number is a number, an ISO date is a date, true is a boolean.
  • A value that starts with =, +, - or @ is text and never a formula. Placeholders inside formulas are refused, so data can never become a formula.
  • To repeat rows, put {{#items}} in a cell of the first row and {{/items}} in a cell of the last. Rows below move down. Formulas, merged cells, conditional formats, filters, defined names, tables, charts and print areas that point at moved rows follow.
  • Formulas in a repeated row follow Excel's fill-down rule. A relative reference moves down with each copy. A $ reference never moves.
  • Saved formula results are dropped and the workbook is marked to recalculate when Excel opens it. A program that does not calculate sees empty formula cells.

Missing values

By default, a placeholder with no value is an error. Fetlar lists all of them with their places and exits with code 65:

fetlar: letter.docx: The template could not be filled (3 problems):
  - no value for {{total | number:"#,##0.00"}} (word/document.xml, paragraph 2: "Your invoice total is {{total | number:"...")
  - no value for {{due | date:"d mmmm yyyy"}} (word/document.xml, paragraph 2: "Your invoice total is {{total | number:"...")
  - no value for {{#items}} (word/document.xml)

Change this with --missing leave (keep the placeholder as written) or --missing empty.

Safety

Data is only data. It is escaped, never read as markup, a formula or a placeholder. No field codes, DDE, links or fonts are written. Warnings, such as a {{ in a place that is not filled, go to stderr.

--strip-external goes further for templates you do not trust. It removes an attached template, signatures, ribbon customizations and add-in panes. It refuses remote pictures, embedded objects, ActiveX, fields that read files and links to other workbooks, with exit code 3.

Pictures come only from data given as data:image/png;base64,... values, or from files inside the folder named by --images DIR. PNG, JPEG, GIF and BMP are accepted. --no-data-uris refuses the data: form.

Options

OptionMeaning
-o, --output OUTthe output file. With --each, the folder
--each PATHone file per item of the array at PATH (items, report.rows, .)
--name PATTERNfile names with {index} and {field}. Default {index}
--missing error|leave|emptywhat to do with a placeholder that has no value
--today YYYY-MM-DDthe date {{@today}} stands for
--images DIRallow pictures from files in this folder
--no-data-urisrefuse pictures given as data: URIs
--compression 0-9deflate level. Default 4
--timeout SECSgive up after this many seconds (exit code 75)
--strip-externalremove or refuse references to anything outside the file
--overwritewith --each, replace files already in the folder
--namesprint the names the template reads, and stop

To make a new template, write a Word or Excel file with fetlar write and put the {{tags}} in its text.

On this page