Spreadsheets Creation (.xlsx)
Use the server function create_document({ format: "xlsx", title, spec }) to generate an Excel spreadsheet.
How to fill the spec
Structure First: Plan the workbook sheets and column widths:
- Sheet name (
name: string) - Explicit column widths (
columnWidths: number[]) - Header row with bold styling and background fill
- Data rows with typed values (numbers, strings, booleans)
- Formula cells (
{ formula: "SUM(C2:C10)", value: 0 }) - Number formats (
format: "$#,##0.00"or"0.0%")
- Sheet name (
Concise Text: Keep headers and cell labels clear and standardized.
Arabic & RTL Handling:
- For Arabic sheets, set
rtl: trueon the sheet or root spec. - Excel will display columns from Right to Left with right-aligned text.
- For Arabic sheets, set
Example Call
{
"format": "xlsx",
"title": "Annual Department Budget",
"spec": {
"rtl": false,
"sheets": [
{
"name": "Q1 Budget",
"columnWidths": [24, 15, 15, 18],
"rows": [
{
"cells": [
{ "value": "Department", "bold": true, "backgroundColor": "E5E7EB" },
{ "value": "Budget", "bold": true, "backgroundColor": "E5E7EB" },
{ "value": "Actual", "bold": true, "backgroundColor": "E5E7EB" },
{ "value": "Variance", "bold": true, "backgroundColor": "E5E7EB" }
]
},
{
"cells": [
"Engineering",
{ "value": 50000, "format": "$#,##0" },
{ "value": 46000, "format": "$#,##0" },
{ "formula": "B2-C2", "value": 4000, "format": "$#,##0" }
]
}
]
}
]
}
}