← 返回
未分类 中文

Excel Export

Generate polished .xlsx workbooks from structured JSON — multiple sheets, frozen headers, filters, typed columns, formulas, totals, and French/Morocco format...
从结构化JSON生成精美的.xlsx工作簿,支持多工作表、冻结表头、筛选、类型化列、公式、合计以及法国/摩洛哥格式。
mohamed-hammane
未分类 clawhub v1.1.0 1 版本 100000 Key: 无需
★ 0
Stars
📥 428
下载
💾 0
安装
1
版本
#latest

概述

When to Use

Use when the agent must deliver a .xlsx Excel file — sales reports, query results, multi-sheet data exports, financial summaries, or any structured data that needs polished spreadsheet formatting. This skill handles workbook creation only. Do not use it to read, edit, or preserve existing Excel files.

Setup

python3 -m venv ~/.openclaw/workspace/.venv_excel
~/.openclaw/workspace/.venv_excel/bin/pip install xlsxwriter

No credentials required.

How to Run

~/.openclaw/workspace/.venv_excel/bin/python skills/excel-export/scripts/build_xlsx.py \
  --input  <path/to/workbook.json> \
  --output <path/to/report.xlsx>

Default export directory: ~/.openclaw/workspace/exports/excel/.

The script prints a JSON summary to stdout on success:

{
  "success": true,
  "output": "/absolute/path/to/report.xlsx",
  "sheets": [
    { "sheet": "Ventes", "rows": 42 },
    { "sheet": "Charges", "rows": 18 }
  ]
}

Input Format

The input is a single JSON file. Top-level shape:

{
  "sheets": [ ... ]
}

Each sheet object:

FieldRequiredDescription
----------------------------------------------------------------
nameyesSheet tab name (max 31 chars)
titlenoBold title row above the table
subtitlenoMuted subtitle row below the title
columnsyesArray of column definitions
rowsnoArray of data objects (keyed by key)

Each column object:

FieldRequiredDescription
--------------------------------------------------------------------------
keyyesRow-object key for this column's values
headeryesDisplay header in the table
typenoData type (default text) — see table below
widthnoExplicit column width (overrides auto-estimate)
numfmtnoCustom Excel number format (overrides type default)
formulanoExcel table structured-reference formula
totalnoTotals-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 validation error.

Column Types

TypeDefault formatNotes
---------------------------------------------------------------------------
textAlways stored as text
integer#,##0Rounded to whole number
number#,##0.00Two decimal places
percent0.0%Pass 0.15 for 15 %
currency#,##0.00 "MAD"Moroccan dirham by default
datedd/mm/yyyyAccepts YYYY-MM-DD strings
datetimedd/mm/yyyy hh:mmAccepts ISO 8601 strings
booleanRendered as Oui / Non

Use numfmt on any column to override its type's default format.

Rendering Rules

Layout — fixed, deterministic, never configured 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 filters, banded rows, and Table Style Medium 9.

Column widths — auto-estimated from headers and sampled values, capped 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 apply 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 datasets — produce a valid workbook with headers, filters, styling, and zero data rows.

Data-Integrity Doctrine

These rules are always enforced — they are not optional:

  1. 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.
  1. 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.
  1. Treat dates explicitly. Dates are serial numbers with legacy quirks. The script writes real date objects with explicit dd/mm/yyyy formatting — never raw serial numbers or ambiguous strings.
  1. Validate before delivery. The script validates every input field, rejects unknown keys, and fails fast with clear error messages. A workbook should never ship with silent data loss.
  1. Regional defaults are French / Morocco. Date format dd/mm/yyyy, currency MAD, booleans Oui / Non. Note: final display still depends partly on the viewer's local Excel regional settings.

Full Example

{
  "sheets": [
    {
      "name": "Ventes Q1",
      "title": "Rapport 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": [
        { "region": "Casablanca", "ca": 1250000, "volume": 340, "growth": 0.15, "date": "2026-03-31", "active": true },
        { "region": "Rabat",      "ca": 980000,  "volume": 210, "growth": -0.03, "date": "2026-03-31", "active": true },
        { "region": "Tanger",     "ca": 670000,  "volume": 155, "growth": 0.08,  "date": "2026-03-31", "active": false }
      ]
    }
  ]
}
~/.openclaw/workspace/.venv_excel/bin/python skills/excel-export/scripts/build_xlsx.py \
  --input  ~/.openclaw/workspace/exports/ventes_q1.json \
  --output ~/.openclaw/workspace/exports/excel/ventes_q1.xlsx

Validation Rules

The script fails fast with a clear error on:

  • Invalid or missing JSON
  • Duplicate sheet names
  • Sheet names exceeding 31 characters, containing [ ] : * ? / \, or starting/ending with apostrophes
  • subtitle without title
  • Row count above 1,048,576 or column count above 16,384
  • Unknown keys in row objects
  • Invalid type or total values
  • Non-string formula definitions
  • Unrecognized boolean values (only true/false, 1/0, yes/no, oui/non accepted)
  • Non-integer values in integer columns (e.g. 12.9 is rejected, not truncated)
  • Unparseable dates, datetimes, or numeric strings in typed columns

SQL-Driven Exports

When generating Excel files from SQL query results, read references/SQL_TO_EXCEL_RECIPE.md for the standard pipeline: query with mssql, normalize values, build the JSON spec, then render. The recipe includes SQL-to-JSON type mappings, normalization rules, ready-made templates, and common mistakes.

Limitations (v1)

  • Creation only — does not read or edit existing workbooks.
  • No template preservation, merged cells, or conditional formatting.
  • One fixed visual theme — no configurable colour system.
  • No CSV input — upstream steps must produce JSON.
  • xlsxwriter does not calculate formulas; the recipient's Excel client recalculates on open.

版本历史

共 1 个版本

  • v1.1.0 当前
    2026-05-03 10:03 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

Chart MPL

mohamed-hammane
使用matplotlib从CSV数据生成PNG/SVG图表(折线、柱状、水平柱状、饼图、堆叠、散点、面积图),用于用户请求可视化表格数据的场景。
★ 0 📥 547

IMAP SMTP Email

mohamed-hammane
使用本地 Node脚本通过 IMAP/SMTP 读取和发送邮件,适用于需要检查收件箱、获取邮件内容、搜索邮件、下载附件等场景。
★ 0 📥 451

PDF Report

mohamed-hammane
使用 Jinja2 和 WeasyPrint 从结构化 JSON 生成整洁的 A4 PDF 报告,适用于需要格式化 PDF 文档的场景,如分析摘要、数据报告等。
★ 0 📥 581