1仕組みと動作原理
docx/pptx と共通の哲学:タスクに応じたツールの選定——数式/書式を伴う作成・編集は openpyxl、バッチデータ処理は pandas、素早いプレビューは markitdown、数式と値の両モデルの読み取りには必ず二重の load_workbook を実施。
| **Read** a model (formulas *and* values) | two `load_workbook` passes — see gotchas
中核となる技術的事実:openpyxl はキャッシュ値を含まない数式文字列のみを書き込むため、数式を含むファイルは納品前に必ず recalc.py を実行する必要がある——LibreOffice を StarBasic マクロ経由で駆動して再計算とインプレース上書きを行い、status/errors_found を含む JSON 規約を返す。
openpyxl writes formulas as strings with **no cached values**. Until you recalculate, every formula cell reads back as `None` to anything reading cached values
数式のポータビリティを納品品質として管理:LO が実装する関数サブセットは Excel より小さく、_xlfn. プレフィックスを付与できない関数や未サポートの関数は #NAME? としてファイルに焼き付いてしまうため、「使用可能/要プレフィックス/使用禁止」の3段階の関数リストを規定。
LibreOffice implements fewer functions than Excel, and one it cannot evaluate becomes a literal `#NAME?` baked into the file you deliver.
「recalc 成功(緑)≠ 数式の正確性」の明示化:許容誤差の間違いや参照行の誤りがある数式もエラー 0 件で通過してしまうため、グリッド全体に展開する前に 2〜3 個の数式を手動検証することを義務付け。
**A green recalc proves your formulas *evaluate*, not that they are *right*.**
外部参照リンク('[1]Returns Analysis'!$B$2)を高リスクとして識別:openpyxl での再保存時にキャッシュ値が失われ、その後の LO による再パースで失敗して全リンクが削除される——recalc.py は外部参照を検出すると即座に実行を拒否し、事前に値をコピーするか --force で損失を容認する必要がある。
if you re-save it with openpyxl and then recalculate. Such a formula reads `='[1]Returns Analysis'!$B$2`
体系化された成果物規律:プロ仕様のフォント選定、すべての前提条件やハードコード数値に対するコメントまたは隣接セルでの出典明記、自作の入力待ちテンプレートへの凡例+サンプル行の付与、既存ファイルの変更時は入力指定セルのみに書き込み数式は触らない、ユーザー仕様の厳密な履行。
**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.
2コア機能
3外部依存関係
| Kind | Dependency / Endpoint |
|---|---|
| package | openpyxl / pandas / markitdown(pip,预装声明,import 失败才装) |
| cli | LibreOffice soffice(recalc 引擎,经 scripts/office/soffice.py 包装,适配无头沙箱) |
| cli | gtimeout(可选,recalc 超时保护) |
4推奨統制措置と判定根拠
- scripts/: ローカルスクリプトまたはコマンドの実行: recalc.py(同梱 Python)→ soffice.py 経由でヘッドレス LibreOffice を起動し組み込み Basic マクロを実行(calculateAll/store)
- 本地工作目录: ファイルの読み書きと成果物の出力: recalc によるワークブックのインプレース上書き(tempdir 内の -env:UserInstallation 一時 LO プロファイルを使用)
5二重目の独立検証
- [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' 一致。
6結論
d680b3f18f0c671a…