xlsx
Use this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved.
1How It Works & Mechanism
Shares the same philosophy as docx/pptx: pick tools by task—use openpyxl for creation/editing with formulas/formatting, pandas for bulk data, markitdown for quick browsing, and a dual load_workbook call when reading the 'formula + value' model.
| **Read** a model (formulas *and* values) | two `load_workbook` passes — see gotchas
Core engineering reality: openpyxl writes only formula strings without cached values; any file containing formulas must undergo recalc.py before delivery—which drives LibreOffice via a StarBasic macro to recalculate and overwrite the file in place, returning a JSON contract with status/errors_found.
openpyxl writes formulas as strings with **no cached values**. Until you recalculate, every formula cell reads back as `None` to anything reading cached values
Formula portability is treated as delivery quality: the subset of functions implemented in LO is smaller than Excel; functions lacking the _xlfn. prefix or unsupported will turn into #NAME? baked into the delivered file, hence a three-tier function list ('usable / needs prefix / forbidden') is maintained.
LibreOffice implements fewer functions than Excel, and one it cannot evaluate becomes a literal `#NAME?` baked into the file you deliver.
'Green recalc ≠ correct formulas' is made explicit: formulas with wrong error margins or referencing incorrect rows still pass with 0 errors, requiring 2-3 sample formula checks before filling the entire grid.
**A green recalc proves your formulas *evaluate*, not that they are *right*.**
External link references ('[1]Returns Analysis'!$B$2) are identified as high-risk: openpyxl resaving loses cached values, and subsequent LO parsing will fail and drop all links—recalc.py refuses to run upon detecting external links, requiring copying values beforehand or using --force to accept losses.
if you re-save it with openpyxl and then recalculate. Such a formula reads `='[1]Returns Analysis'!$B$2`
A systematic deliverable discipline: professional typography, comments or adjacent cells detailing sources for every assumption/hardcoded number, legends + sample rows for self-built fill-in templates, modifying only designated input cells while leaving formulas untouched in existing files, and strictly executing user specs.
**Follow the user's spec literally.** Exact tab names, exact column headers, and the formula they spelled out. A redesign that computes something else fails, however elegant.
2Core Capabilities
3External Dependencies
| Kind | Dependency / Endpoint |
|---|---|
| package | openpyxl / pandas / markitdown(pip,预装声明,import 失败才装) |
| cli | LibreOffice soffice(recalc 引擎,经 scripts/office/soffice.py 包装,适配无头沙箱) |
| cli | gtimeout(可选,recalc 超时保护) |
4Recommended Governance & Evidence
- scripts/: Execute local script or command: recalc.py (bundled Python) → launches LibreOffice headless via soffice.py to execute embedded Basic macro (calculateAll/store)
- 本地工作目录: File read/write and artifact output: recalc overwrites the workbook in place (-env:UserInstallation temporary LO profile in tempdir)
5Second-Pass Verification
- [ok] recalc JSON 契约与退出码语义 — 代码返回 dict 含 status/errors_found 等键;main 中 'sys.exit(1 if "error" in result else 0)' 与 SKILL 'only that case exits non-zero' 一致。
- [ok] 外链拒跑机制 — external_links_at_risk() 扫描 xl/externalLinks/ 并匹配 EXTERNAL_REF_RE,SKILL 所述 'refuses to run in that state' 有代码对应(force 分支)。
- [ok] LibreOffice 宏重算 — RECALCULATE_MACRO 内嵌 'Sub RecalculateAndSave() … ThisComponent.calculateAll() ThisComponent.store()',经临时 profile 执行。
- [ok] 共享 office/ 工具树 — xlsx/scripts/office 与 docx、pptx 的对应目录 diff 零差异(同一文件副本)。
- [ok] 网络/凭证零命中 — 脚本无网络调用、无 env/token 读取;pip 仅条件回退。
- [ok] 夸大检查 — description 'Use this skill any time a spreadsheet file is the primary input or output' 覆盖 open/read/edit/create/convert/clean 均在正文有路线;'Do NOT trigger when…Google Sheets API integration' 负面边界明确。
- [ok] 元数据 — 本地 HEAD==pin 41bbe19;LICENSE 专有(© 2025 Anthropic, PBC.)与 frontmatter 'Proprietary' 一致。
6Verdict & Scenarios
d680b3f18f0c671a…