Autorun AI Docs

13. Excel Templates

Two ways to work with spreadsheets from a process: fill a prepared template, or build and read workbooks directly with the bundled XLSX library.


generateExcelTemplate(values, templateId)

async · returns string (Base64)

Fills a stored .xlsx template with your values and returns the rendered workbook, Base64 encoded.

Prop

Type

const base64 = await context.functions.generateExcelTemplate(
  {
    Month: "March 2026",
    Total: 85000,
    Rows: orders.records.map(o => ({ Number: o.ID, Client: o.ClientName, Amount: o.Amount }))
  },
  "a3f92b10-8c4d-4e11-9f22-77c1b0e4d5a6"
);

await context.functions.update("reports", context.record.ID, { FileData: base64 });

templateId is the file id of the uploaded template, not a name. Anything other than an object for values is treated as an empty map, so the template renders with all placeholders blank rather than failing.

You only get the bytes back

The function returns Base64 and nothing else — no filename, no content type, no extension. A macro-enabled .xlsm template stays macro-enabled after filling, but the process has no way to discover that. Track the expected extension yourself alongside the template id.


The XLSX library

For anything the template engine cannot express — reading an uploaded workbook, merging sheets, generating a file with no template — SheetJS is available as a global called XLSX.

Loaded only when mentioned

The library is injected only if the text XLSX appears in your node's code, so processes that never touch spreadsheets pay nothing for it. The check is a literal string match on the source, which means XLSX must appear verbatim — building the name dynamically leaves it undefined.

Reading an uploaded spreadsheet

/** @event afterCreate @entity imports */
const file = await context.functions.GetFileAsync(context.record.FileId);
if (!file) throw new Error("Uploaded file could not be read");

const workbook = XLSX.read(file.bytes, { type: "array" });
const sheet = workbook.Sheets[workbook.SheetNames[0]];
const rows = XLSX.utils.sheet_to_json(sheet);

log("Parsed " + rows.length + " rows from " + file.filename);

const result = await context.functions.createBulk("customers",
  rows.map(r => ({ Name: r.Name, Email: r.Email, Phone: r.Phone }))
);

if (!result.success) {
  throw new Error(result.failureCount + " of " + rows.length + " rows could not be imported");
}

Building a workbook

const orders = await context.functions.get("orders", { pagination: { skip: 0, take: 5000 } });

const sheet = XLSX.utils.json_to_sheet(orders.records.map(o => ({
  Order: o.ID,
  Client: o.ClientName,
  Amount: o.Amount,
  Date: o.CreateDate
})));

const workbook = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(workbook, sheet, "Orders");

const base64 = XLSX.write(workbook, { type: "base64", bookType: "xlsx" });
await context.functions.update("reports", context.record.ID, { FileData: base64 });

Building the file this way sidesteps the 5,000-row cap that applies to generateExcel, though you still have to page through the data yourself and stay within the process timeout.


Choosing between them

You want toUse
Fill a designed workbook — branding, formulas, formattinggenerateExcelTemplate
Export rows with no particular stylinggenerateExcel (see Document Generation)
Read a spreadsheet a user uploadedXLSX.read
Build a workbook with custom structure or beyond 5,000 rowsXLSX.utils and XLSX.write
XLSX is not available while debugging on every node

The library is loaded per node, based on that node's source. If you split spreadsheet work across several nodes, each one that uses it must reference XLSX in its own code.