Docs / Word and Excel templates

Templates

Word and Excel templates

Some documents need to stay editable: contracts a lawyer will mark up, spreadsheets a customer will keep working in. For those, design the template in Word or Excel, put {{placeholders}} in it, and DevilPDF fills it with your data.

The output is always the same format as the template. A Word template produces a .docx, an Excel template produces an .xlsx.

Important: DevilPDF does not convert Word or Excel files to PDF. If you need a PDF, build an HTML template instead. They are designed for print and give you exact control over pages.

#Upload a template

In the dashboard, create a new template under Templates and choose to upload a Word or Excel file. Or use the API, with the file as base64 or an https URL:

curl https://devilpdf.com/v1/templates/upload \
  -H "Authorization: Bearer $DEVILPDF_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{
    \"name\": \"Service agreement\",
    \"file\": \"$(base64 -w0 agreement.docx)\",
    \"sample_data\": { \"client\": { \"name\": \"Acme Robotics Inc.\" } }
  }"
FieldTypeDescription
filestringRequired. The .docx or .xlsx file as base64, or an https URL to download it from. Up to 10 MB.
namestringTemplate name. Defaults to the filename without its extension.
filenamestringOriginal file name, used for the default name.
descriptionstringUp to 500 characters.
sample_dataobjectExample data, for your own reference.

The response is a template object with "kind": "docx" or "kind": "xlsx". The file type is detected from its contents. Old binary formats (.doc, .xls) are not supported; save them as .docx or .xlsx first.

#Render

Render it like any other template. Leave format out: the output is always the template's own format. Asking for "format": "pdf" or an image format returns invalid_request.

curl https://devilpdf.com/v1/render \
  -H "Authorization: Bearer $DEVILPDF_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "template": "tpl_Hn4vK9sQe2Lx7Wp0Zt3b",
    "data": {
      "client": { "name": "Acme Robotics Inc.", "address": "2200 Mission Street\nSan Francisco, CA" },
      "start_date": "March 14, 2026",
      "services": [
        { "name": "Brand identity system", "fee": "$4,800" },
        { "name": "Marketing site design", "fee": "$7,200" }
      ],
      "rush": true
    },
    "filename": "acme-service-agreement"
  }'

The document in the response has "format": "docx" and a link to the filled file. output, filename, expires_in, destination, metadata, async and batches all work as usual. options and pdf do not apply.

#Word placeholders

Type placeholders straight into the document, in the text, in tables, in headers and footers. They take on the formatting of the text around them.

PlaceholderMeaning
{{client.name}}A value. Dots reach into nested objects.
{{#services}} ... {{/services}}Repeat the content between the tags for each item in an array.
{{#rush}} ... {{/rush}}Show the content only when the value is true (or non-empty).
{{^rush}} ... {{/rush}}Show the content only when the value is false, empty or missing.
{{.}}The current item, inside a loop over plain strings or numbers.

#Loops

Inside a loop, placeholders refer to the current item. Names not found on the item are looked up in the surrounding data, so {{client.name}} still works inside {{#services}}.

To repeat a table row, put the opening tag in the first cell of the row and the closing tag in the last:

ServiceFee
{{#services}}{{name}}{{fee}}{{/services}}

To repeat whole paragraphs, put the opening and closing tags on their own lines. Those lines are removed from the output.

#Good to know

  • Line breaks (\n) in a value become line breaks in the document.
  • A missing value prints nothing.
  • Values are inserted as text. Format numbers, dates and currency in your code before you send them. The Liquid filters of HTML templates are not available here.
  • If Word has split a placeholder into pieces with different formatting, it is still recognised. If a tag is not closed, or a loop is closed in the wrong order, the render fails with a template_error that names the problem.

#Excel placeholders

Type {{placeholders}} into cells.

Cell containsResult
{{invoice.number}}The value. If it is a number in your JSON, the cell becomes a real numeric cell.
Invoice {{invoice.number}}Text with the value inserted.
  • Numeric cells mean formulas that reference them keep working. The workbook recalculates when it is opened.
  • A missing value leaves the cell empty.
  • Excel templates fill single values. There are no loops, so a sheet cannot grow by one row per item. For tabular data of varying length, use an HTML template, or lay out a fixed number of rows.
  • Number formats, column widths, charts and other sheets are left as they are.

#Limits

Each filled file counts as one document. Templates themselves are unlimited on every plan.