Excel Export — Excel 导出
v1生成 polished .xlsx workbooks from structured JSON — multiple sheets, frozen headers, 过滤器s, typed columns, formulas, totals, and French/Morocco 格式化ting defaults. Use when the user needs database 结果s or 上下文-derived data 导出ed as an Excel file.
运行时依赖
安装命令
点击复制技能文档
When to Use
Use when the 代理 must deliver a .xlsx Excel file — sales 报告s, 查询 结果s, multi-sheet data 导出s, financial summaries, or any structured data that needs polished spreadsheet 格式化ting. This 技能 handles workbook creation only. Do not use it to read, edit, or preserve existing Excel files.
设置up python3 -m venv ~/.OpenClaw/workspace/.venv_excel ~/.OpenClaw/workspace/.venv_excel/bin/pip 安装 xlsxwriter
No 凭证s required.
How to 运行 ~/.OpenClaw/workspace/.venv_excel/bin/python 技能s/excel-导出/scripts/build_xlsx.py \ --输入 \ --输出
Default 导出 directory: ~/.OpenClaw/workspace/导出s/excel/.
The script prints a JSON summary to stdout on 成功:
{ "成功": true, "输出": "/absolute/path/to/报告.xlsx", "sheets": [ { "sheet": "Ventes", "rows": 42 }, { "sheet": "Charges", "rows": 18 } ] }
输入 格式化
The 输入 is a single JSON file. Top-level shape:
{ "sheets": [ ... ] }
Each sheet object:
Field Required Description name yes Sheet tab name (max 31 chars) title no Bold title row above the table subtitle no Muted subtitle row below the title columns yes Array of column definitions rows no Array of data objects (keyed by key)
Each column object:
Field Required Description key yes Row-object key for this column's values header yes Display header in the table type no Data type (default text) — see table below width no Explicit column width (overrides auto-estimate) numfmt no Custom Excel number 格式化 (overrides type default) formula no Excel table structured-reference formula total no Totals-row function: sum, average, or count
Rows are objects keyed by column key, not positional arrays. Missing keys produce blank cells. Unknown keys cause a 验证 error.
Column Types Type Default 格式化 Notes text — Always stored as text integer #,##0 Rounded to whole number number #,##0.00 Two decimal places percent 0.0% Pass 0.15 for 15 % currency #,##0.00 "MAD" Moroccan dirham by default date dd/mm/yyyy Accepts YYYY-MM-DD strings datetime dd/mm/yyyy hh:mm Accepts ISO 8601 strings boolean — Rendered as Oui / Non
Use numfmt on any column to override its type's default 格式化.
Rendering Rules
Layout — fixed, deterministic, never 配置d per-sheet:
No title/subtitle → table header on row 1. Title only → title row 1, blank row 2, table header row 3. Title + subtitle → title row 1, subtitle row 2, blank row 3, table header row 4.
Freeze pane — always at the first data row (A2, A4, or A5 depending on title presence).
Table style — each sheet is one rectangular Excel table with 过滤器s, banded rows, and Table Style Medium 9.
Column widths — auto-estimated from headers and sampled values, c应用ed at 50 characters. Explicit width in the column definition overrides the estimate.
Formulas — use Excel structured references (e.g. =[@Revenue]/SUM([Revenue])). Formula columns are injected through the table definition, not written cell-by-cell, so they 应用ly to every data row automatically.
Totals row — if any column has total, the table includes a totals row. The first column displays "Total" as a label unless it has its own total function.
Empty data设置s — produce a valid workbook with headers, 过滤器s, styling, and zero data rows.
Data-Integrity Doctrine
These rules are always enforced — they are not optional:
Preserve data types. Leading-zero strings, phone numbers (+212…), and numeric strings longer than 15 digits are always stored as text. Excel silently corrupts these if written as numbers.
Keep calculations in Excel. When the workbook should stay live, write formulas — not hardcoded derived values from Python. Use structured references so formulas survive row insertions and deletions.
Treat dates explicitly. Dates are serial numbers with legacy quirks. The script writes real date objects with explicit dd/mm/yyyy 格式化ting — never raw serial numbers or ambiguous strings.
验证 before delivery. The script 验证s every 输入 field, rejects unknown keys, and fAIls fast with clear error messages. A workbook should never ship with silent data loss.
Regional defaults are French / Morocco. Date 格式化 dd/mm/yyyy, currency MAD, booleans Oui / Non. Note: final display still depends partly on the viewer's local Excel regional 设置tings.
Full Example { "sheets": [ { "name": "Ventes Q1", "title": "R应用ort des Ventes — Q1 2026", "subtitle": "Direction Commerciale", "columns": [ { "key": "region", "header": "Région", "type": "text" }, { "key": "ca", "header": "CA (MAD)", "type": "currency", "total": "sum" }, { "key": "volume", "header": "Volume", "type": "integer", "total": "sum" }, { "key": "growth", "header": "Croissance", "type": "percent" }, { "key": "date", "header": "Date", "type": "date" }, { "key": "active", "header": "Actif", "type": "boolean" } ], "rows": [