officecli-xlsx
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseOfficeCLI XLSX Skill
OfficeCLI XLSX Skill
Setup
安装配置
If is missing:
officecli- macOS / Linux:
curl -fsSL https://d.officecli.ai/install.sh | bash - Windows (PowerShell):
irm https://d.officecli.ai/install.ps1 | iex
Verify with (open a new terminal if PATH hasn't picked up). If install fails, download a binary from https://github.com/iOfficeAI/OfficeCLI/releases.
officecli --version如果缺少:
officecli- macOS / Linux:
curl -fsSL https://d.officecli.ai/install.sh | bash - Windows (PowerShell):
irm https://d.officecli.ai/install.ps1 | iex
使用验证安装(若PATH未更新,需打开新终端)。若安装失败,可从https://github.com/iOfficeAI/OfficeCLI/releases下载二进制文件。
officecli --version⚠️ Help-First Rule
⚠️ 优先求助规则
This skill teaches what good xlsx looks like, not every command flag. When a property name, enum value, or alias is uncertain, consult help BEFORE guessing.
bash
officecli help xlsx # List all xlsx elements
officecli help xlsx <element> # Full element schema (e.g. pivottable, chart, cf)
officecli help xlsx <verb> <element> # Verb-scoped (e.g. add chart, set cell)
officecli help xlsx <element> --json # Machine-readable schemaHelp reflects the installed CLI version. When this skill and help disagree, help is authoritative.
此技能旨在传授优质xlsx文件的规范,而非所有命令参数。当不确定属性名称、枚举值或别名时,请先查阅帮助文档,切勿猜测。
bash
officecli help xlsx # 列出所有xlsx相关元素
officecli help xlsx <element> # 查看元素完整架构(如pivottable、chart、cf)
officecli help xlsx <verb> <element> # 按动词范围查看(如add chart、set cell)
officecli help xlsx <element> --json # 查看机器可读格式的架构帮助文档与已安装的CLI版本同步。若此技能内容与帮助文档存在冲突,以帮助文档为准。
Shell & Execution Discipline
Shell与执行规范
Shell quoting (zsh / bash). Excel paths contain , and number formats contain . Both are shell metacharacters. Rules:
[]$- ALWAYS quote element paths: , not
"/Sheet1/row[1]"./Sheet1/row[1] - Use single quotes for any prop value containing :
$.numFmt='$#,##0' - For formulas with cross-sheet references, use
!with abatchheredoc (see Known Issues).<<'EOF' - and
\nin a prop value ARE interpreted by the CLI —\tis a real in-cell line break (pair with\n),--prop wrapText=truea tab — consistent across xlsx / docx / pptx. Double them (\t) for a literal backslash-n (rarely wanted). (\\nis the shell layer above — single-quote it.)$
Incremental execution. Run commands one at a time and read each exit code. mutates the file on every call; a 50-command script that fails at command 3 will cascade silently. One command → check output → continue.
officecliShell引号规则(zsh / bash)。Excel路径包含,数字格式包含,两者均为Shell元字符。规则如下:
[]$- 务必为元素路径添加引号:,而非
"/Sheet1/row[1]"。/Sheet1/row[1] - 若属性值包含,请使用单引号:
$。numFmt='$#,##0' - 对于包含跨表引用的公式,使用
!配合batchheredoc语法(详见已知问题)。<<'EOF' - 属性值中的和
\n会被CLI解析——\t表示单元格内的真实换行(需搭配\n),--prop wrapText=true表示制表符——此规则在xlsx / docx / pptx中通用。若需表示字面意义的反斜杠加n,需写为\t(极少用到)。(\\n属于Shell层,需用单引号包裹。)$
增量执行。每次仅运行一条命令并查看退出码。会在每次调用时修改文件;若一个包含50条命令的脚本在第3条命令失败,后续错误会无声蔓延。应遵循:执行一条命令 → 检查输出 → 继续执行。
officecliRequirements for Outputs
输出要求
Before reaching for a command, know what a good xlsx looks like. These are the deliverable standards every workbook MUST meet.
在执行命令前,需明确优质xlsx文件的标准。以下是所有工作簿必须满足的交付规范。
All Excel files
所有Excel文件通用规范
Zero formula errors. Every delivered workbook MUST have ZERO , , , , . No exceptions — guard denominators with or .
#REF!#DIV/0!#VALUE!#NAME?#N/AIFERRORIF(x=0,...)Formulas, not hardcoded values. If a number can be computed from other cells, it is a formula. Hardcoding where belongs breaks the contract that the workbook stays live when inputs change. This is the single most important rule in this skill.
5000=SUM(B2:B9)Professional font. Use one consistent, professional font across the workbook (Arial / Calibri / Times New Roman). Don't mix four fonts because one sheet came from CSV.
Explicit widths. There is no auto-fit. Any column the user will read MUST have set — default 8.43 chars clips everything. Sensible starts: labels 20-25, numbers 12-15, dates 12, short codes 8-10.
widthPreserve existing templates. When editing a file that already has a look, match it. Existing conventions override these guidelines.
零公式错误。交付的每个工作簿必须完全没有、、、、错误。无例外——需用或保护分母。
#REF!#DIV/0!#VALUE!#NAME?#N/AIFERRORIF(x=0,...)使用公式而非硬编码值。若某个数值可通过其他单元格计算得出,则必须使用公式。在应使用的位置硬编码,会破坏工作簿在输入变化时动态更新的约定。这是此技能中最重要的规则。
=SUM(B2:B9)5000专业字体。整个工作簿使用统一的专业字体(Arial / Calibri / Times New Roman)。切勿因某张工作表来自CSV就混用四种字体。
明确列宽。不支持自动适配。用户需要查看的任何列必须设置——默认8.43字符会截断内容。合理的初始值:标签列20-25字符,数字列12-15字符,日期列12字符,短编码列8-10字符。
width保留现有模板样式。编辑已有样式的文件时,需匹配原有格式。现有约定优先于本指南的规则。
Visual delivery floor (applies to EVERY workbook)
视觉交付底线(适用于所有工作簿)
Before you declare done, run and Read the returned HTML path to confirm all of these:
officecli view "$FILE" html- No in any cell.
###means a column is too narrow for its widest value. Every column the user reads needs an explicit###.widthin a delivered file is unfinished work, never "a small visual nit".### - No truncated titles. Sheet titles, section headers, long labels must fit. Widen the column or apply on the cell.
wrapText=true - No placeholder tokens rendered as data. ,
$fy$24,{var},<TODO>must never appear in a cell, chart title, series name, or legend. These are build-time tokens that escaped replacement.xxxx - Pie / doughnut slices have distinct fill colors. If the slices render same-colored, switch to /
baror setcolumnexplicitly.colors=... - No empty trailing pages / empty chart anchors. over empty source cells looks like a broken chart.
anchor=D2:J18
If any of the above fails, STOP and fix before declaring done.
Print layout. Any sheet the user may print or send as a board pack needs page setup. Default portrait + no fit-to-page splits wide tables and charts mid-way. Pick the fit mode by sheet shape:
bash
undefined在宣告完成前,运行并查看返回的HTML路径,确认以下所有要求:
officecli view "$FILE" html- 单元格中无。
###表示列宽不足以容纳最宽的内容。用户需要查看的每一列都需设置明确的###。交付文件中出现width属于未完成工作,绝非“小视觉瑕疵”。### - 标题无截断。工作表标题、章节标题、长标签必须完整显示。可加宽列宽或为单元格设置。
wrapText=true - 无占位符令牌作为数据显示。、
$fy$24、{var}、<TODO>绝不能出现在单元格、图表标题、系列名称或图例中。这些是构建时的令牌,不应遗漏替换。xxxx - 饼图/环形图切片颜色区分明显。若切片颜色相同,切换为/
bar图表,或显式设置column。colors=... - 无空尾页/空图表锚点。指向空数据源单元格时,会显示为损坏的图表。
anchor=D2:J18
若上述任何一项不满足,请立即停止并修复,再宣告完成。
打印布局。用户可能打印或作为董事会材料发送的工作表,需进行页面设置。默认纵向+未设置适配页面会导致宽表和图表被中途拆分。根据工作表形状选择适配模式:
bash
undefinedSummary / chart / dashboard sheet (small, ≤ ~40 rows): fit to a single page.
摘要/图表/仪表板工作表(内容较少,≤约40行):适配为单页。
officecli set "$FILE" "/Summary" --prop orientation=landscape --prop fitToPage=true
officecli set "$FILE" "/Summary" --prop orientation=landscape --prop fitToPage=true
Tall data table (dozens+ rows): fit WIDTH only, let height paginate naturally.
长数据表(数十行以上):仅适配宽度,高度自然分页。
fitToPage=true here crushes every row onto one page → unreadable (### dates, 5px rows).
此处使用fitToPage=true会将所有行压缩到一页→内容无法读取(日期显示###,行高5px)。
officecli set "$FILE" "/Data" --prop orientation=landscape --prop fitToPage=1x0
`fitToPage=true` == `1x1` == fit both axes to one page — correct only when the sheet is already short. `1x0` = fit 1 page wide, unlimited pages tall. Trigger: sheet holds a chart, or > 8 columns, or the user's ask mentions print / board / investor.officecli set "$FILE" "/Data" --prop orientation=landscape --prop fitToPage=1x0
`fitToPage=true` == `1x1` == 同时适配宽高到单页——仅适用于内容已较短的工作表。`1x0` = 适配为1页宽,高度不限。触发场景:工作表包含图表、超过8列,或用户需求提及打印/董事会/投资者。Financial models only — skip this section if you are building a template, tracker, CSV import, or operational sheet
仅适用于财务模型——若构建模板、追踪器、CSV导入或运营工作表,请跳过本节
Scope: budgets, forecasts, 3-statement models, valuation, any -heavy analytical workbook. A customer-support tracker or onboarding template does not need this section.
$Color coding — industry standard. Five core colors used as a language, not decoration. A reviewer should tell what a cell IS by color alone — before reading the formula.
| Color | Role | Example |
|---|---|---|
Blue text | Hardcoded inputs, scenario variables | |
Black text | ALL formulas and calculations | default |
Green text | Cross-sheet links inside this workbook | |
Red text | Links to external files / workbooks | |
Yellow fill | Key assumptions needing review | |
A reviewer should tell what a cell IS just by its color — before reading the formula. This is a communication contract, not a cosmetic preference.
Number formatting — standards, not preferences.
- Years are text, not numbers. Format not
2026— use2,026or setnumFmt="@".type=string - Currency carries its unit in the header (), not in every cell.
Revenue ($mm) - Zeros display as , not
-. Use0.$#,##0;($#,##0);"-" - Percentages default to one decimal: .
0.0% - Negatives use parentheses: not
(1,234).-1,234 - Valuation multiples use format (EV/EBITDA, P/E, etc.).
0.0x
Assumptions live in cells, not inside formulas. is correct; is a bug. Document each blue hardcoded input with an adjacent source note in the next cell or a cell comment:
=B5*(1+$B$6)=B5*1.05Source: Company 10-K, FY2024, Page 45, Revenue Note
Source: Bloomberg, 2026-05-02, AAPL US Equity
Source: Management guidance, Q2 2026 earnings callAny hardcoded number without a source is an undocumented assumption — a reviewer cannot audit it.
适用范围:预算、预测、三表模型、估值、任何以为主的分析工作簿。客户支持追踪器或入职模板无需遵循本节规则。
$颜色编码——行业标准。五种核心颜色作为一种语言使用,而非装饰。审阅者应仅通过颜色就能判断单元格类型——无需查看公式。
| 颜色 | 作用 | 示例 |
|---|---|---|
蓝色文本 | 硬编码输入、场景变量 | |
黑色文本 | 所有公式和计算结果 | 默认 |
绿色文本 | 工作簿内的跨表链接 | |
红色文本 | 指向外部文件/工作簿的链接 | |
黄色填充 | 需要审阅的关键假设 | |
审阅者应仅通过颜色就能判断单元格类型——无需查看公式。这是沟通约定,而非 cosmetic 偏好。
数字格式——标准而非偏好。
- 年份为文本,而非数字。格式应为而非
2026——使用2,026或设置numFmt="@"。type=string - 货币单位放在表头(如),而非每个单元格中。
Revenue ($mm) - 零值显示为,而非
-。使用格式0。$#,##0;($#,##0);"-" - 百分比默认保留一位小数:。
0.0% - 负值使用括号:而非
(1,234)。-1,234 - 估值倍数使用格式(如EV/EBITDA、P/E等)。
0.0x
假设存于单元格,而非公式内。是正确写法;属于错误。每个蓝色硬编码输入需在相邻单元格或单元格批注中记录来源:
=B5*(1+$B$6)=B5*1.05来源:公司10-K报告,2024财年,第45页,收入附注
来源:彭博,2026-05-02,AAPL美国股票
来源:管理层指引,2026年第二季度财报电话会议任何无来源的硬编码数字均为未记录的假设——审阅者无法审核。
Common Workflow
通用工作流
Six steps. Every non-trivial build follows this shape.
- Open/save lifecycle. Use at the start and
officecli open <file>at the end to flush to disk —officecli save <file>only writes and leaves the resident warm for follow-up edits; reach forsaveonly to release the resident on a one-shot handoff. Both are always safe (never error or lose work). For many cells, useofficecli close <file>: ≤ 50 ops/block recommended; tested up to 80+ ops per block on pure value-set payloads with zero failures. Cross-sheet formula batches are the exception — run those non-resident, single heredoc (see Known Issues). Flush only at the non-officecli boundary: officecli's own reads always see your edits; runbatch/saveonly before a non-officecli program reads the file (openpyxl/pandas, Excel, a renderer, delivery).close - Create or load. (new) or
officecli create "$FILE"(existing — get the lay of the land first).officecli view "$FILE" outline - Build incrementally. One command, read the output, continue. After any structural op (new sheet, chart, named range, pivot), run on it to confirm shape before stacking more on top.
get - Format. Column widths, number formats, freeze panes, tab colors, header fills. Formatting is not optional polish — per "Requirements for Outputs" it is part of the deliverable.
- Save, then reckon with the cache. writes to disk. Newly-added formulas ship without cached values; when a human opens the file in a spreadsheet app, the app recalculates and populates them. But your downstream
officecli save <file>,INDEX/MATCH, or any formula that references an upstream formula will cache whatever the upstream cached at write-time — oftenSUMPRODUCTor a stale value — and that cached lie survives into non-recalculating readers. After any multi-formula build involving array formulas (0,SUMPRODUCTwith dynamic criteria) or cross-sheet chains, re-touch every downstream cell (runSUMIFSagain with the same formula) so the engine recomputes its cache from the freshly-cached upstream. ⚠️ Re-touch on cross-sheet chains via resident is unreliable (see Batch / resident caveats) — prefer non-residentsetfor the re-touch pass. Thenseta few downstream cells and eyeball that theirofficecli getis plausible.cachedValue=is safe with a resident open and itself flushes pending edits to disk (same as docx / pptx).validate - QA — assume there are problems. See the QA section. You are not done when your last command exited 0; you are done after one fix-and-verify cycle finds zero new issues.
六个步骤。所有非 trivial 的构建均遵循此流程。
- 打开/保存生命周期。开始时使用,结束时使用
officecli open <file>将修改写入磁盘——officecli save <file>仅写入文件并保持内存缓存活跃,以便后续编辑;仅在一次性交付时使用save释放内存缓存。两者均安全(不会报错或丢失数据)。处理大量单元格时,使用officecli close <file>:建议每个块≤50个操作;纯设置值的 payload 测试过支持80+操作/块,无失败。跨表公式批处理除外——需使用非缓存模式,单个 heredoc(详见已知问题)。仅在非officecli边界时刷新:officecli自身的读取始终能看到你的修改;仅在非officecli程序(openpyxl/pandas、Excel、渲染器、交付)读取文件前,运行batch/save。close - 创建或加载。(新建)或
officecli create "$FILE"(现有文件——先了解整体结构)。officecli view "$FILE" outline - 增量构建。执行一条命令,查看输出,再继续。完成任何结构性操作(新建工作表、图表、命名区域、数据透视表)后,运行命令确认结构,再进行后续操作。
get - 格式化。设置列宽、数字格式、冻结窗格、标签颜色、表头填充。格式化并非可选的润色——根据“输出要求”,它是交付内容的一部分。
- 保存,然后处理缓存。将修改写入磁盘。新增的公式不会附带缓存值;当人类用户在电子表格应用中打开文件时,应用会重新计算并填充缓存值。但下游的
officecli save <file>、INDEX/MATCH或任何引用上游公式的公式,会缓存上游写入时的缓存值——通常为SUMPRODUCT或过期值——且该错误缓存会保留到不重新计算的读取器中。完成任何涉及数组公式(0、带动态条件的SUMPRODUCT)或跨表链的多公式构建后,重新处理每个下游单元格(再次运行SUMIFS命令,使用相同公式),让引擎根据上游新缓存的值重新计算其缓存。⚠️ 通过缓存模式重新处理跨表链不可靠(详见批处理/缓存注意事项)——建议使用非缓存模式的set进行重新处理。然后使用set查看几个下游单元格,确认officecli get的值合理。cachedValue=命令在缓存模式下打开文件时也安全,且会自动将待处理的修改写入磁盘(与docx/pptx相同)。validate - QA——假设存在问题。详见QA章节。并非最后一条命令执行成功就完成了;需经过一次修复-验证循环,确认未发现新问题,才算完成。
Quick Start
快速入门
Minimal viable xlsx: 3 months of revenue + a total formula + column widths + a currency format. Adapt, don't copy-paste — your file, your data.
bash
officecli create "$FILE"
officecli open "$FILE"
officecli set "$FILE" /Sheet1/A1 --prop value=Month --prop bold=true
officecli set "$FILE" /Sheet1/B1 --prop value=Revenue --prop bold=true
officecli set "$FILE" /Sheet1/A2 --prop value=Jan
officecli set "$FILE" /Sheet1/A3 --prop value=Feb
officecli set "$FILE" /Sheet1/A4 --prop value=Mar
officecli set "$FILE" /Sheet1/B2 --prop value=42000 --prop numFmt='$#,##0'
officecli set "$FILE" /Sheet1/B3 --prop value=45000 --prop numFmt='$#,##0'
officecli set "$FILE" /Sheet1/B4 --prop value=48000 --prop numFmt='$#,##0'
officecli set "$FILE" /Sheet1/A5 --prop value=Total --prop bold=true
officecli set "$FILE" /Sheet1/B5 --prop formula="SUM(B2:B4)" --prop bold=true --prop numFmt='$#,##0'
officecli set "$FILE" "/Sheet1/col[A]" --prop width=12
officecli set "$FILE" "/Sheet1/col[B]" --prop width=15
officecli close "$FILE"
officecli validate "$FILE"Verified: returns , resolves to . This is the shape of every build: open → set cells/formulas → format → close → validate.
validateno errors foundB5135000最简xlsx示例:3个月收入数据 + 总计公式 + 列宽 + 货币格式。请根据你的文件和数据调整,不要直接复制粘贴。
bash
officecli create "$FILE"
officecli open "$FILE"
officecli set "$FILE" /Sheet1/A1 --prop value=Month --prop bold=true
officecli set "$FILE" /Sheet1/B1 --prop value=Revenue --prop bold=true
officecli set "$FILE" /Sheet1/A2 --prop value=Jan
officecli set "$FILE" /Sheet1/A3 --prop value=Feb
officecli set "$FILE" /Sheet1/A4 --prop value=Mar
officecli set "$FILE" /Sheet1/B2 --prop value=42000 --prop numFmt='$#,##0'
officecli set "$FILE" /Sheet1/B3 --prop value=45000 --prop numFmt='$#,##0'
officecli set "$FILE" /Sheet1/B4 --prop value=48000 --prop numFmt='$#,##0'
officecli set "$FILE" /Sheet1/A5 --prop value=Total --prop bold=true
officecli set "$FILE" /Sheet1/B5 --prop formula="SUM(B2:B4)" --prop bold=true --prop numFmt='$#,##0'
officecli set "$FILE" "/Sheet1/col[A]" --prop width=12
officecli set "$FILE" "/Sheet1/col[B]" --prop width=15
officecli close "$FILE"
officecli validate "$FILE"验证:返回,计算结果为。这是所有构建的流程:打开→设置单元格/公式→格式化→关闭→验证。
validateno errors foundB5135000CSV / bulk import
CSV / 批量导入
Native command (preferred for CSV/TSV). Fastest path; loads a CSV into a sheet in one call. sets AutoFilter + freeze pane on row 1. Widths and still need a follow-up pass (per D-12 in Dashboard skill).
import--headernumFmtbash
officecli import "$FILE" /Sheet1 --file data.csv --header
officecli import "$FILE" /Sheet1 --file data.tsv --format tsv --header
officecli import "$FILE" /Sheet1 --stdin --start-cell B2 < data.csvPython + batch fallback — use when you need custom type coercion, formula injection, or the CSV lives inside another data pipeline. Recipe for 600-6000+ cells:
python
undefined原生命令(CSV/TSV首选)。最快的方式;一次调用即可将CSV加载到工作表中。参数会在第1行设置自动筛选+冻结窗格。仍需后续设置列宽和(详见仪表板技能的D-12)。
import--headernumFmtbash
officecli import "$FILE" /Sheet1 --file data.csv --header
officecli import "$FILE" /Sheet1 --file data.tsv --format tsv --header
officecli import "$FILE" /Sheet1 --stdin --start-cell B2 < data.csvPython + batch 备选方案——当需要自定义类型转换、公式注入,或CSV属于其他数据管道时使用。适用于600-6000+单元格的场景:
python
undefinedgen_batch.py — produces batch chunks of 80 value-set ops each
gen_batch.py —— 生成每个块包含80个设置值操作的批处理数据
import csv, json
ops = []
with open("data.csv") as f:
reader = csv.reader(f)
for r, row in enumerate(reader, start=1):
for c, val in enumerate(row):
col = chr(ord('A') + c)
ops.append({"command":"set","path":f"/Data/{col}{r}",
"props":{"value": val}})
for i in range(0, len(ops), 80):
print(json.dumps(ops[i:i+80]))
```bash
python gen_batch.py | while IFS= read -r chunk; do
printf '%s\n' "$chunk" | officecli batch "$FILE"
doneOutcome: 648-row retail CSV (6490 cells) loads in ~30s, zero failures. Tune: start at 80 ops/chunk, drop to 40 if any chunk fails. Numeric type inference and formulas come later via targeted — batch in this recipe is pure value injection.
setimport csv, json
ops = []
with open("data.csv") as f:
reader = csv.reader(f)
for r, row in enumerate(reader, start=1):
for c, val in enumerate(row):
col = chr(ord('A') + c)
ops.append({"command":"set","path":f"/Data/{col}{r}",
"props":{"value": val}})
for i in range(0, len(ops), 80):
print(json.dumps(ops[i:i+80]))
```bash
python gen_batch.py | while IFS= read -r chunk; do
printf '%s\n' "$chunk" | officecli batch "$FILE"
done结果:648行零售CSV(6490个单元格)加载耗时约30秒,无失败。调整:初始设置为80操作/块,若任何块失败,降至40操作/块。数值类型推断和公式需后续通过针对性的命令设置——此示例中的batch仅用于纯值注入。
setReading & Analysis
读取与分析
Start wide, then narrow. first tells you what sheets exist and where the data is; jump into / / only once you know where to look.
outlineviewgetqueryOpen the rendered workbook to eyeball your own work.
- — Read the returned HTML to audit the rendered output. Each sheet is addressable, charts render inline. Catches
officecli view $FILE html, placeholder leakage, pivot layout, row-height clipping.### - keeps a live preview running for the human user — they open it at their own discretion. Use when the user wants to watch along; agent self-check uses
officecli watch $FILEabove. Useview htmlas your first visual check after a batch of edits — fix at source. For final visual verification, the user opens theview htmlin their Excel / WPS / Numbers viewer..xlsx
Orient. Sheets, dimensions, formula counts.
bash
officecli view "$FILE" outlineExtract. Plain text dump for content QA or LLM context; scope with / / for big files.
--start--end--colsbash
officecli view "$FILE" text --start 1 --end 50 --cols A,B,COther modes worth knowing: (cell values + types/formulas + warnings), (numeric summaries), (broken formulas, empty sheets, missing refs).
viewannotatedstatsissuesRound-trip dump. serializes the workbook — or one worksheet (, ) — into a replayable batch JSON; replays it. Use it to learn from an existing workbook's structure or clone/adapt a template instead of reading raw OOXML. Coverage per ; subtree dumps don't carry workbook-level resources (settings, named ranges) — the replay target must already define them.
officecli dump "$FILE" [path]/Sheet1/sheet[N]officecli batch new.xlsx --input dump.jsondump --helpbash
officecli dump "$FILE" -o blueprint.json # whole workbook
officecli dump "$FILE" /Sheet1 -o sheet.json # one worksheet
officecli batch new.xlsx --input blueprint.jsonInspect one element. Use XPath-style paths. Always quote — shells glob .
[N]bash
officecli get "$FILE" "/Sheet1/A1" # one cell
officecli get "$FILE" "/Sheet1/A1:D10" # range
officecli get "$FILE" "/Sheet1/chart[1]" # chart
officecli get "$FILE" "/Sheet1/table[1]" # ListObject
officecli get "$FILE" "/namedrange[1]" # workbook-level named rangeAdd to expand children; add for machine output. Full element list: .
--depth N--jsonofficecli help xlsxQuery across the workbook. CSS-like selectors. Use for systematic checks (formula coverage, error cells, empty headers) rather than hand-walking.
bash
officecli query "$FILE" 'cell:has(formula)' # every formula cell
officecli query "$FILE" 'cell:contains("#REF!")' # broken references
officecli query "$FILE" 'cell[type=Number]' # typed filter
officecli query "$FILE" 'Sheet1!B[value!=0]' # sheet-scopedOperators: , , (contains), , , (exists).
=!=~=>=<=[attr]Merge cells shortcut. or — both are aliases for . Returns every merged range in the workbook without hand-walking entries.
officecli query $FILE mergemergedrangemergeCell<mergeCell>When the data is big enough that a row-walk is useless, reach for Excel's own analytical elements:
- Build a pivot table with (
officecli add) to group/aggregate without writing 20 SUMIFs. Attach a slicer (--type pivottable) to give the reader a filter UI.--type slicer - Drop a sparkline () in a row to show per-row trends — cheaper than one line chart per row and they print inline.
--type sparklineis a strict enum:type(plus aliasesline | column | stacked/winloss→win-loss). Invalidstackedvalues hard-fail — no silent fallback totype=anymore.line - Run ,
officecli help xlsx pivottable,officecli help xlsx slicerfor the exact prop names.officecli help xlsx sparkline
先全局查看,再聚焦细节。首先使用命令了解工作表结构和数据位置;明确目标后再使用//命令。
outlineviewgetquery打开渲染后的工作簿查看自己的工作成果。
- —— 查看返回的HTML路径,审核渲染后的输出。每个工作表均可访问,图表内嵌显示。可发现
officecli view $FILE html、占位符遗漏、数据透视表布局、行高截断等问题。### - 为用户保持实时预览——用户可自行决定是否打开。适用于用户需要实时查看的场景;Agent自检使用上述
officecli watch $FILE命令。 将view html作为批量编辑后的首次视觉检查工具——从源头修复问题。最终视觉验证可让用户在Excel/WPS/Numbers查看器中打开view html文件。.xlsx
了解结构。查看工作表、维度、公式数量。
bash
officecli view "$FILE" outline提取内容。纯文本导出,用于内容QA或LLM上下文;处理大文件时,可使用//参数限定范围。
--start--end--colsbash
officecli view "$FILE" text --start 1 --end 50 --cols A,B,C其他值得了解的模式:(单元格值+类型/公式+警告)、(数值汇总)、(损坏的公式、空工作表、缺失的引用)。
viewannotatedstatsissues往返导出。将工作簿——或单个工作表(、)——序列化为可重放的batch JSON;可重放该JSON。用于学习现有工作簿的结构,或克隆/适配模板,无需读取原始OOXML。覆盖范围详见;子树导出不包含工作簿级资源(设置、命名区域)——重放目标需已定义这些资源。
officecli dump "$FILE" [path]/Sheet1/sheet[N]officecli batch new.xlsx --input dump.jsondump --helpbash
officecli dump "$FILE" -o blueprint.json # 整个工作簿
officecli dump "$FILE" /Sheet1 -o sheet.json # 单个工作表
officecli batch new.xlsx --input blueprint.json查看单个元素。使用XPath风格的路径。务必添加引号——Shell会解析。
[N]bash
officecli get "$FILE" "/Sheet1/A1" # 单个单元格
officecli get "$FILE" "/Sheet1/A1:D10" # 单元格范围
officecli get "$FILE" "/Sheet1/chart[1]" # 图表
officecli get "$FILE" "/Sheet1/table[1]" # ListObject
officecli get "$FILE" "/namedrange[1]" # 工作簿级命名区域添加参数展开子元素;添加参数获取机器可读输出。完整元素列表:。
--depth N--jsonofficecli help xlsx跨工作簿查询。使用类CSS选择器。用于系统性检查(公式覆盖、错误单元格、空表头),而非手动遍历。
bash
officecli query "$FILE" 'cell:has(formula)' # 所有包含公式的单元格
officecli query "$FILE" 'cell:contains("#REF!")' # 损坏的引用
officecli query "$FILE" 'cell[type=Number]' # 按类型筛选
officecli query "$FILE" 'Sheet1!B[value!=0]' # 工作表范围筛选运算符:、、(包含)、、、(存在)。
=!=~=>=<=[attr]合并单元格快捷方式。或——两者均为的别名。无需手动遍历条目,即可返回工作簿中的所有合并范围。
officecli query $FILE mergemergedrangemergeCell<mergeCell>当数据量大到手动遍历无意义时,使用Excel自身的分析元素:
- 使用(
officecli add)构建数据透视表,无需编写20个SUMIF函数即可分组/聚合数据。添加切片器(--type pivottable)为读者提供筛选UI。--type slicer - 在行中添加迷你图()显示每行的趋势——比每行一个折线图更简洁,且可内嵌打印。
--type sparkline为严格枚举值:type(别名line | column | stacked/winloss对应win-loss)。无效的stacked值会直接失败——不再默认回退到type=。line - 查看、
officecli help xlsx pivottable、officecli help xlsx slicer获取准确的属性名称。officecli help xlsx sparkline
Creating & Editing
创建与编辑
Ninety percent of a build is cells, formulas, formatting, and one or two charts. The verbs: (new element), (change a prop), , , , .
addsetremovemoveswapbatch90%的构建工作涉及单元格、公式、格式化和一两个图表。可用动词:(新增元素)、(修改属性)、、、、。
addsetremovemoveswapbatchCells and formulas
单元格与公式
Set a value and its format in one call. Never write at the start of a formula — the CLI strips it.
=bash
officecli set "$FILE" /Sheet1/B5 --prop formula="SUM(B2:B4)" --prop numFmt='$#,##0'
officecli set "$FILE" /Sheet1/C5 --prop formula="B5/A5" --prop numFmt="0.0%"Structural properties (width, height, freeze, tabColor) live on row / col / sheet nodes:
bash
officecli set "$FILE" "/Sheet1/col[A]" --prop width=20
officecli set "$FILE" "/Sheet1/row[1]" --prop height=22
officecli set "$FILE" "/Sheet1" --prop freeze=A2 --prop tabColor=1F4E79一次调用即可设置值和格式。公式开头无需写——CLI会自动去除。
=bash
officecli set "$FILE" /Sheet1/B5 --prop formula="SUM(B2:B4)" --prop numFmt='$#,##0'
officecli set "$FILE" /Sheet1/C5 --prop formula="B5/A5" --prop numFmt="0.0%"结构性属性(宽度、高度、冻结、标签颜色)属于行/列/工作表节点:
bash
officecli set "$FILE" "/Sheet1/col[A]" --prop width=20
officecli set "$FILE" "/Sheet1/row[1]" --prop height=22
officecli set "$FILE" "/Sheet1" --prop freeze=A2 --prop tabColor=1F4E79Named ranges
命名区域
Prefer named ranges over in formulas. They self-document ( beats ) and they let you move the assumption cell without breaking formulas. Because values contain both and , add them through a batch heredoc:
$B$6GrowthRate$B$6ref!$bash
cat <<'EOF' | officecli batch "$FILE"
[
{"command":"add","parent":"/","type":"namedrange","props":{"name":"GrowthRate","ref":"Sheet1!$B$6"}}
]
EOFSee for the full schema.
officecli help xlsx namedrangeBatch JSON does NOT accept shell aliases. Inside batch , always use the full dotted name — , , never (ambiguous: text vs fill). On a bare cell, even the shell form is rejected: errors with . Rule: in any batch JSON or cell prop, write / explicitly. should be for workbook-level elements and for sheet-scoped; empty string is not equivalent.
props"font.color": "FF0000""font.size": 14"color": "FF0000"--prop color=1F4E79ambiguous in cell context — use 'font.color' (text) or 'fill' (bg)font.colorfillparent"/""/SheetName"在公式中优先使用命名区域,而非。命名区域可自我文档化(比更清晰),且移动假设单元格时不会破坏公式。由于值包含和,需通过batch heredoc添加:
$B$6GrowthRate$B$6ref!$bash
cat <<'EOF' | officecli batch "$FILE"
[
{"command":"add","parent":"/","type":"namedrange","props":{"name":"GrowthRate","ref":"Sheet1!$B$6"}}
]
EOF查看获取完整架构。
officecli help xlsx namedrangeBatch JSON不接受Shell别名。在batch的中,必须使用完整的点式名称——、,而非(存在歧义:文本颜色还是填充颜色)。在单个单元格的Shell命令中,也会报错:。规则:在任何batch JSON或单元格属性中,需显式写/。对于工作簿级元素应为,对于工作表级元素应为;空字符串不等效。
props"font.color": "FF0000""font.size": 14"color": "FF0000"--prop color=1F4E79ambiguous in cell context — use 'font.color' (text) or 'fill' (bg)font.colorfillparent"/""/SheetName"Charts
图表
Chart types live under — the enum is long (20+). Pick the right one for the message: column for category comparison, line for time series, pie only when slices are self-evidently proportional, scatter for correlation. Avoid exotic types unless they answer a specific question.
officecli help xlsx chartThree ways to feed chart data. Pick one per chart — mixing them at add-time is a common trap.
| Form | Shape | When to use |
|---|---|---|
(a) inline | | Tiny demo charts, numbers you will not edit. Source of truth lives in the chart XML, not a cell. |
(b) 2D | | Normal case. Must be 2-D — single column fails with "Chart requires data". |
| (c) dotted per-series | | Multi-series charts where each series points at non-contiguous ranges, or you want explicit series naming. |
The single-column trap. looks like "value column" but the engine rejects it with . Either widen the range to include the category column (), or switch to form (c) with explicit .
dataRange="Sheet1!B2:B13"Chart requires dataA2:B13series1.categoriesMove / resize a chart after create: (also ). Series are still immutable — to add/change a series, the chart and with the full series list. Note shifts and re-add appends at the end — to preserve chart order, remove all and rebuild in order.
set chart[N] --prop anchor="F5:N25"--prop x= --prop y= --prop width= --prop height=officecli removeofficecli addremove chart[1]chart[2] → chart[1]Anchor sizing. No auto-fit. A column chart with 5-6 categories + 2 series needs roughly (12 cols × 18 rows) to show all labels uncut. Narrower and X-axis labels clip; wider and the chart can split across pages on print/export. If in doubt, start narrow, preview via (Read the returned HTML path), widen in increments. Page layout (below) is the other half of the fix.
A5:L22view htmlChart — always prefix with the sheet. Even when the chart lives on the same sheet, write , not . The sheet-less form works inconsistently; the prefixed form is 100% reliable.
dataRangedataRange="Summary!A17:C22"A17:C22officecli adds extended chart types the classic Excel object model lacks: , , , , , , . Use them when the data calls for them.
boxWhiskerwaterfallfunnelhistogramtreemapsunburstparetoNEVER put unreplaced template tokens in chart title / series name / legend / axis title. , , , , render literally in the legend — validate passes, but a CFO sees where "FY2024" should be. Always bind to final text or a cell reference ( or ).
$fy$24{var}<TODO>$VAR{{placeholder}}$fy$24title="FY2024 Revenue"series1.name="Sheet1!A1"图表类型详见——枚举值超过20种。根据要传达的信息选择合适的类型:柱状图用于类别比较,折线图用于时间序列,饼图仅适用于切片比例直观的场景,散点图用于相关性分析。除非有特定需求,否则避免使用特殊类型。
officecli help xlsx chart三种图表数据输入方式。每个图表仅选一种——添加时混用是常见陷阱。
| 形式 | 格式 | 使用场景 |
|---|---|---|
(a) 内联 | | 小型演示图表,无需编辑的数值。数据源存储在图表XML中,而非单元格。 |
(b) 二维 | | 常规场景。必须为二维——单列会报错“Chart requires data”。 |
| (c) 按系列分点设置 | | 多系列图表,每个系列指向非连续范围,或需要显式命名系列。仅设置 |
单列陷阱。看似是“值列”,但引擎会报错“Chart requires data”。需将范围扩大到包含类别列(),或切换为形式(c)并显式设置。
dataRange="Sheet1!B2:B13"A2:B13series1.categories创建后移动/调整图表大小:(也可使用)。系列创建后不可修改——若要添加/修改系列,需图表,再完整的系列列表。注意会将变为,重新添加会追加到末尾——若要保留图表顺序,需删除所有图表后按顺序重建。
set chart[N] --prop anchor="F5:N25"--prop x= --prop y= --prop width= --prop height=officecli removeofficecli addremove chart[1]chart[2]chart[1]锚点大小。不支持自动适配。包含5-6个类别+2个系列的柱状图,锚点大小约为(12列×18行),才能完整显示所有标签。锚点过窄会导致X轴标签截断,过宽会导致图表在打印/导出时跨页。若不确定,先设置较小的锚点,通过预览(查看返回的HTML路径),逐步加宽。页面布局(见下文)是另一部分解决方案。
A5:L22view html图表——务必添加工作表前缀。即使图表与数据在同一工作表,也需写,而非。无工作表前缀的写法不稳定,带前缀的写法100%可靠。
dataRangedataRange="Summary!A17:C22"A17:C22officecli支持经典Excel对象模型没有的扩展图表类型:、、、、、、。当数据需要时使用这些类型。
boxWhiskerwaterfallfunnelhistogramtreemapsunburstpareto切勿在图表标题/系列名称/图例/轴标题中保留未替换的模板令牌。、、、、会在图例中按字面显示——会通过,但CFO会看到而非“FY2024”。始终绑定到最终文本或单元格引用(或)。
$fy$24{var}<TODO>$VAR{{placeholder}}validate$fy$24title="FY2024 Revenue"series1.name="Sheet1!A1"Conditional formatting
条件格式
Three common flavors, each with its own prop shape (consult ):
officecli help xlsx cf- Color scales: cells shaded on a gradient by value — with
type=colorscale/minColor/midColor.maxColor - Data bars: in-cell bars showing magnitude — . Set explicit
type=databar/minfor consistent scaling across a column; defaults are valid if you omit them.max - Formula rules (the element): highlight row when a condition is true —
formulacfwithtype=formulaand a fill/font.formula="$C2>1000"
Rule: apply CF sparingly. A workbook where every cell is colored tells the reader nothing.
三种常见类型,每种类型的属性格式不同(查看):
officecli help xlsx cf- 色阶:单元格根据值以渐变颜色填充——,设置
type=colorscale/minColor/midColor。maxColor - 数据条:单元格内显示条形图表示数值大小——。为了在列中保持一致的缩放比例,可显式设置
type=databar/min;若省略则使用默认值。max - 公式规则(元素):满足条件时高亮整行——
formulacf,设置type=formula和填充/字体样式。formula="$C2>1000"
规则:谨慎使用条件格式。每个单元格都着色的工作簿无法为读者提供有效信息。
Data validation
数据验证
Input cells in trackers and templates MUST carry data validation. It's cheap and it stops entire classes of downstream bugs. Three list-source patterns — pick based on where the allowed values live.
(a) Inline list — allowed values are short and fixed in the rule itself.
bash
officecli add "$FILE" /Sheet1 --type validation \
--prop sqref="C2:C100" --prop type=list \
--prop formula1="Yes,No,Maybe" \
--prop showError=true --prop errorTitle="Invalid" --prop error="Select from list"(b) Named range (preferred for cross-sheet lookups) — allowed values live in another sheet and may grow. Define the named range first, then reference it. Use a batch heredoc because contains and :
ref!$bash
cat <<'EOF' | officecli batch "$FILE"
[
{"command":"add","parent":"/","type":"namedrange","props":{"name":"StatusList","ref":"Lookups!$A$2:$A$4"}},
{"command":"add","parent":"/Sheet1","type":"validation","props":{"sqref":"B2:B100","type":"list","formula1":"=StatusList"}}
]
EOF(c) Direct cross-sheet range — no named range, raw inside . Also needs a batch heredoc to keep and intact:
Lookups!$A$2:$A$4formula1!$bash
cat <<'EOF' | officecli batch "$FILE"
[
{"command":"add","parent":"/Sheet1","type":"validation","props":{"sqref":"C2:C100","type":"list","formula1":"Lookups!$A$2:$A$4"}}
]
EOFIf you write the cross-sheet variant as on the shell, the gets shell-mangled into and the dropdown will silently fall back to no list. Verify with — must show a plain , no backslash.
--prop formula1=...!\!officecli get "$FILE" /Sheet1/validation[N]formula1=!Other common values: , , , , . See for operators and the full prop list.
typedecimalwholedatetextLengthcustomofficecli help xlsx validation追踪器和模板中的输入单元格必须设置数据验证。成本低且能避免大量下游错误。三种列表来源模式——根据允许值的存储位置选择。
(a) 内联列表——允许值较短且固定在规则中。
bash
officecli add "$FILE" /Sheet1 --type validation \
--prop sqref="C2:C100" --prop type=list \
--prop formula1="Yes,No,Maybe" \
--prop showError=true --prop errorTitle="Invalid" --prop error="Select from list"(b) 命名区域(跨表查找首选)——允许值存储在另一个工作表中,且可能增长。先定义命名区域,再引用它。由于包含和,需使用batch heredoc:
ref!$bash
cat <<'EOF' | officecli batch "$FILE"
[
{"command":"add","parent":"/","type":"namedrange","props":{"name":"StatusList","ref":"Lookups!$A$2:$A$4"}},
{"command":"add","parent":"/Sheet1","type":"validation","props":{"sqref":"B2:B100","type":"list","formula1":"=StatusList"}}
]
EOF(c) 直接跨表范围——不使用命名区域,直接在中写。同样需要batch heredoc来保留和:
formula1Lookups!$A$2:$A$4!$bash
cat <<'EOF' | officecli batch "$FILE"
[
{"command":"add","parent":"/Sheet1","type":"validation","props":{"sqref":"C2:C100","type":"list","formula1":"Lookups!$A$2:$A$4"}}
]
EOF若在Shell中写,会被Shell解析为,下拉列表会无声失效。使用验证——必须显示纯,无反斜杠。
--prop formula1=...!\!officecli get "$FILE" /Sheet1/validation[N]formula1=!其他常见的值:、、、、。查看获取运算符和完整属性列表。
typedecimalwholedatetextLengthcustomofficecli help xlsx validationOther elements (one-liners)
其他元素(单行命令)
- Tables (ListObjects) — with a range; gives auto-filter + structured refs.
add --type table.officecli help xlsx table - Comments — ; use for documenting hardcoded assumptions.
add --type comment.officecli help xlsx comment - Sheet reordering — , not
officecli move.swaponly works on row/cell paths.swap
- 表格(ListObjects)——并设置范围;提供自动筛选+结构化引用。查看
add --type table。officecli help xlsx table - 批注——;用于记录硬编码假设。查看
add --type comment。officecli help xlsx comment - 工作表重排序——使用,而非
officecli move。swap仅适用于行/单元格路径。swap
Chart Axis-by-Role
按角色编辑图表轴
Editing a chart axis in place is cheaper than rebuilding the chart. Address axes by role ( = Y, = X), not by index — the XML order isn't stable.
valuecategorybash
officecli get "$FILE" "/Sheet1/chart[1]/axis[@role=value]"
officecli set "$FILE" "/Sheet1/chart[1]/axis[@role=value]" --prop min=0 --prop max=100000
officecli set "$FILE" "/Sheet1/chart[1]/axis[@role=category]" --prop title="Month"Safe props: , , , , , .
titleminmaxmajorGridlinesvisiblelabelRotation就地编辑图表轴比重建图表更高效。按角色(=Y轴,=X轴)寻址轴,而非按索引——XML顺序不稳定。
valuecategorybash
officecli get "$FILE" "/Sheet1/chart[1]/axis[@role=value]"
officecli set "$FILE" "/Sheet1/chart[1]/axis[@role=value]" --prop min=0 --prop max=100000
officecli set "$FILE" "/Sheet1/chart[1]/axis[@role=category]" --prop title="Month"安全属性:、、、、、。
titleminmaxmajorGridlinesvisiblelabelRotationQA (Required)
QA(必填)
Assume there are problems. Your job is to find them.
Your first workbook is almost never correct. Treat QA as a bug hunt, not a confirmation step. If you found zero issues on first inspection, you were not looking hard enough. The formulas look fine until you check two of them against source cells.
假设存在问题。你的任务是找出这些问题。
你的第一个工作簿几乎不可能完全正确。将QA视为漏洞排查,而非确认步骤。若首次检查未发现任何问题,说明你检查得不够仔细。公式看起来没问题直到你将其中两个与源单元格对比。
Minimum cycle before "done"
宣告“完成”前的最小检查周期
- — empty sheets, broken formulas, missing refs.
officecli view "$FILE" issues - (sample ranges) — values + types + warnings.
officecli view "$FILE" annotated - For every Excel error type, query it:
bash
officecli query "$FILE" 'cell:contains("#REF!")' officecli query "$FILE" 'cell:contains("#DIV/0!")' officecli query "$FILE" 'cell:contains("#VALUE!")' officecli query "$FILE" 'cell:contains("#NAME?")' officecli query "$FILE" 'cell:contains("#N/A")' - — safe with a resident open;
officecli validate "$FILE"flushes pending edits to disk itself.validate - Visual pass — walk every sheet via the HTML preview. Run and Read the returned HTML path. Each sheet renders with charts inline. Scan for
officecli view "$FILE" html, truncated titles, placeholder tokens (###,$fy$24,{var}), sliced charts, white-slice pie charts, empty chart anchors — STOP and fix before declaring done. "validate pass" is not delivery; "the preview looks like a real workbook" is delivery. For human preview, run<TODO>(user opens the live preview at their own discretion) or have them open theofficecli watch "$FILE"directly in Excel / WPS / Numbers..xlsx - Print layout fix (wide tables / multi-chart sheets). When a sheet holds a chart or a wide table and the user will print it, set per-sheet page layout — but match the fit mode to the sheet's height:
Outcome: charts/wide tables print without mid-chart splits; tall tables stay readable across natural page breaks. Apply to every sheet that holds a chart or a > 8-column table.bash
# Short summary / chart sheet → fit to one page. officecli set "$FILE" "/Summary" --prop orientation=landscape --prop fitToPage=true # Tall data table → fit width only (fitToPage=true would crush all rows onto one unreadable page). officecli set "$FILE" "/Data" --prop orientation=landscape --prop fitToPage=1x0 - If anything failed, fix, then rerun the full cycle. One fix commonly creates another problem.
officecli view issuesview htmlissuesview html###- —— 检查空工作表、损坏的公式、缺失的引用。
officecli view "$FILE" issues - (抽样范围)—— 查看值+类型+警告。
officecli view "$FILE" annotated - 针对每种Excel错误类型进行查询:
bash
officecli query "$FILE" 'cell:contains("#REF!")' officecli query "$FILE" 'cell:contains("#DIV/0!")' officecli query "$FILE" 'cell:contains("#VALUE!")' officecli query "$FILE" 'cell:contains("#NAME?")' officecli query "$FILE" 'cell:contains("#N/A")' - —— 在缓存模式下打开文件时也安全;
officecli validate "$FILE"会自动将待处理的修改写入磁盘。validate - 视觉检查——通过HTML预览遍历每个工作表。运行并查看返回的HTML路径。每个工作表内嵌显示图表。扫描
officecli view "$FILE" html、截断的标题、占位符令牌(###、$fy$24、{var})、切片错误的图表、白色切片的饼图、空图表锚点——停止并修复后再宣告完成。“validate通过”不等于可交付;“预览看起来像真实的工作簿”才是可交付标准。若需用户预览,可运行<TODO>(用户自行打开实时预览),或让用户直接在Excel/WPS/Numbers中打开officecli watch "$FILE"文件。.xlsx - 修复打印布局(宽表/多图表工作表)。当工作表包含图表或宽表,且用户需要打印时,设置工作表级页面布局——但需根据工作表高度选择适配模式:
结果:图表/宽表打印时不会中途拆分;长表在自然分页时保持可读。对所有包含图表或超过8列的工作表应用此设置。bash
# 短摘要/图表工作表→适配为单页。 officecli set "$FILE" "/Summary" --prop orientation=landscape --prop fitToPage=true # 长数据表→仅适配宽度(fitToPage=true会将所有行压缩到一页,无法读取)。 officecli set "$FILE" "/Data" --prop orientation=landscape --prop fitToPage=1x0 - 若任何检查失败,修复后重新运行完整检查周期。一次修复通常会引发另一个问题。
officecli view issuesview htmlissuesview html###Formula verification checklist
公式验证清单
- Pick 2-3 formulas at random. Run on each. Confirm the formula string is what you intended and
officecli getis what you expect — arithmetic in your head.cachedValue= - Cached value sanity on every summary cell. Any cell that aggregates (COUNTA / COUNTIF / SUMPRODUCT / INDEX&MATCH) must have a plausible . If a progress tracker shows
cachedValueon a blank template, the cache is lying — re-touch the formula via199 / 199 / 100%(forces recompute) or manually set a correct cached value. Do NOT ship "validate passes but the numbers are fiction".set - Spot-check one cell per numeric column. columns showing integer
%throughout means the denominator is wrong or the numerator is cached stale — investigate one cell, fix the pattern.0.0% - Ranges include every row: off-by-one on when data goes to
SUM(B2:B12)is the most common bug.B13 - Cross-sheet formulas () contain no
Sheet1!A1. If\!showsofficecli get, theSheet1\!A1was shell-corrupted — delete and re-enter via batch/heredoc.! - Named ranges () point at what their names claim.
officecli get "$FILE" "/namedrange[1]" - Every denominator is guarded —
/orIFERROR(x/y, 0).IF(y=0, 0, x/y) - Chart data vs source cells: for every chart with inline data, spot-check data points against of the source cells.
officecli get - Chart title / series name / legend contain no unreplaced tokens (,
$...$,{var}). Grep the chart via<TODO>.officecli get /Sheet1/chart[N]
- 随机选择2-3个公式。对每个公式运行。确认公式字符串符合预期且
officecli get的值符合你的计算预期。cachedValue= - 每个汇总单元格的缓存值合理性。任何聚合单元格(COUNTA/COUNTIF/SUMPRODUCT/INDEX&MATCH)的必须合理。若进度追踪器在空白模板中显示
cachedValue,说明缓存错误——需通过199 / 199 / 100%重新处理公式(强制重新计算),或手动设置正确的缓存值。切勿交付“validate通过但数值虚假”的文件。set - 抽查每个数值列的一个单元格。若列全部显示整数
%,说明分母错误或分子缓存过期——调查一个单元格,修复整个模式。0.0% - 范围包含所有行:而数据到
SUM(B2:B12),这是最常见的错误。B13 - 跨表公式()中无
Sheet1!A1。若\!显示officecli get,说明Sheet1\!A1被Shell解析损坏——删除并通过batch/heredoc重新输入。! - 命名区域()指向的位置与名称一致。
officecli get "$FILE" "/namedrange[1]" - 每个分母都有保护——
/或IFERROR(x/y, 0)。IF(y=0, 0, x/y) - 图表数据与源单元格一致:对于每个内联数据的图表,抽查数据点与获取的源单元格值是否一致。
officecli get - 图表标题/系列名称/图例中无未替换的令牌(、
$...$、{var})。通过<TODO>查看图表内容。officecli get /Sheet1/chart[N]
Template QA
模板QA
When editing a template, check for leftover placeholders — they look like content and slip past :
validatebash
officecli query "$FILE" 'cell:contains("{{")'
officecli query "$FILE" 'cell:contains("xxxx")'
officecli query "$FILE" 'cell:contains("TBD")'编辑模板时,检查是否有遗留的占位符——它们看起来像内容,且能通过:
validatebash
officecli query "$FILE" 'cell:contains("{{")'
officecli query "$FILE" 'cell:contains("xxxx")'
officecli query "$FILE" 'cell:contains("TBD")'Fresh eyes
换个视角检查
When you finish a workbook, open it fresh. Read / HTML preview top-to-bottom as if you are a new reviewer — look for formulas, numbers that look off, formatting inconsistency, missing data.
view text完成工作簿后,重新打开它。像新审阅者一样从上到下查看/HTML预览——查找公式、异常数值、格式不一致、缺失数据。
view textHonest limit
诚实的局限性
validatevalidatevalidatevalidateKnown Issues & Pitfalls
已知问题与陷阱
The cross-sheet !
trap (short)
!跨表!
陷阱(简短版)
!Shells (bash history expansion, zsh splitting) and CLI arg parsing mangle in into . A formula containing is silently broken — it renders as literal text and references nothing.
!Sheet1!A1\!\!Fix. Use a batch heredoc with single-quoted delimiter (), which disables all shell expansion:
<<'EOF'bash
cat <<'EOF' | officecli batch "$FILE"
[{"command":"set","path":"/Summary/B2","props":{"formula":"Revenue!B13"}}]
EOFVerify. After writing, the cell; must show a plain with no backslash.
officecli getformula=!Shell(bash历史扩展、zsh拆分)和CLI参数解析会将中的解析为。包含的公式会无声损坏——按字面文本显示,不引用任何内容。
Sheet1!A1!\!\!修复方法。使用带单引号分隔符的batch heredoc(),禁用所有Shell扩展:
<<'EOF'bash
cat <<'EOF' | officecli batch "$FILE"
[{"command":"set","path":"/Summary/B2","props":{"formula":"Revenue!B13"}}]
EOF验证。写入后,使用查看单元格;必须显示纯,无反斜杠。
officecli getformula=!CLI bug backlog (short)
CLI bug 待办事项(简短版)
CLI constraints and gaps to work around — not defects in the output file.
- Chart series are immutable after create — to add/change a series: +
removewith the full series list. (Position is mutable:add/set chart[N] --prop anchor=.)x/y/width/heightshifts subsequent indices down; re-add appends at end.remove chart[N] - Cross-sheet formula batches run fine through a resident — a prior "deadlocks even at 3-5 ops" caution no longer reproduces. Pure value-set batches stay reliable at 50-80+ ops too. If you ever hit a hang, fall back to a non-resident one-big-batch or individual . Multiple resident processes on the same file/machine can still contend — expect non-deterministic hangs if another agent/session holds a resident on the same file.
set - Conditional formatting naming asymmetry — the element name for is
--type; the path suffix isconditionalformatting. Use/cf[N]for schema,officecli help xlsx conditionalformattingfor paths./cf[N] - Sheet prop on add — help says Add processes
position, but the prop is often ignored. Reorder withposition/officecli move --index/--afterafter creating the sheet.--before - cascade guard — rejects sheet remove/rename when the sheet is referenced by validation / conditional format / sparkline / hyperlink / named range on another sheet. Remove those dependent elements first, then remove the sheet.
remove /sheet[N] - Batch JSON rejects cell alias — inside batch
color,propserrors"color": "FF0000". The CLI at shell level acceptsambiguous in cell context — use 'font.color' (text) or 'fill' (bg)/--prop color=...as aliases on non-cell elements, but inside batch JSON on a cell always write the full dotted name:--prop size=14,"font.color","font.size"."font.name"
CLI的约束和需要规避的漏洞——并非输出文件的缺陷。
- 图表系列创建后不可修改——若要添加/修改系列:+
remove完整的系列列表。(位置可修改:add/set chart[N] --prop anchor=。)x/y/width/height会将后续索引下移;重新添加会追加到末尾。remove chart[N] - 跨表公式批处理在缓存模式下运行正常——之前“3-5个操作就会死锁”的警告不再重现。纯设置值的批处理在50-80+操作时仍可靠。若遇到挂起,可回退到非缓存模式的单一大批处理或单个命令。同一文件/机器上的多个缓存进程仍可能冲突——若其他Agent/会话持有同一文件的缓存,可能出现非确定性挂起。
set - 条件格式命名不对称——对应的元素名称为
--type;路径后缀为conditionalformatting。使用/cf[N]查看架构,使用officecli help xlsx conditionalformatting作为路径。/cf[N] - 添加工作表时的属性——帮助文档说明Add会处理
position,但该属性常被忽略。创建工作表后,使用position/officecli move --index/--after重新排序。--before - 级联保护——当工作表被其他工作表的验证/条件格式/迷你图/超链接/命名区域引用时,拒绝删除/重命名工作表。需先删除这些依赖元素,再删除工作表。
remove /sheet[N] - Batch JSON拒绝单元格别名——在batch的
color中,props会报错"color": "FF0000"。Shell级别的CLI在非单元格元素上接受ambiguous in cell context — use 'font.color' (text) or 'fill' (bg)/--prop color=...作为别名,但在单元格的batch JSON中,必须写完整的点式名称:--prop size=14、"font.color"、"font.size"。"font.name"
Renderer caveats (cross-viewer color fidelity)
渲染器注意事项(跨查看器颜色保真度)
officecli view html- Pie / doughnut fill colors may collapse to a single theme tint in some viewers (slices look "all white" or "all one color"). The file may be fine in the user's target viewer.
- Line chart / column chart series colors may drift from the workbook theme in some viewers.
- Form-control checkboxes may render as double-boxed in some viewers.
Before calling a color or chart "broken", open the file in the user's actual target viewer. If it looks correct there, the problem is viewer rendering, not data — do not chase it. The CLI's structural checks (, truncation, placeholder text, layout) remain authoritative.
###officecli view html- 饼图/环形图填充颜色在某些查看器中可能统一为单一主题色调(切片看起来“全白”或“同一种颜色”)。文件在用户的目标查看器中可能显示正常。
- 折线图/柱状图系列颜色在某些查看器中可能偏离工作簿主题。
- 表单控件复选框在某些查看器中可能显示为双框。
在判定颜色或图表“损坏”前,先在用户的实际目标查看器中打开文件。若在目标查看器中显示正常,则问题出在查看器渲染,而非数据——无需处理。CLI的结构性检查(、截断、占位符文本、布局)仍为权威标准。
###Escape layers (shell quoting is above; these are the extras)
转义层(Shell引号在上;以下是额外层)
$\n\t- JSON level (batch). Standard JSON escapes — ,
"\n","\t". A real backslash in the final string is"\""."\\\\" - Excel level. in a cell is a real line break — pair with
\nso Excel shows the wrap. Works in a shell-quoted prop directly (--prop wrapText=true);--prop value='a\nb'inside batch JSON gives the same. When in doubt,"\n"the cell and compare character-for-character.officecli get
$\n\t- JSON层(batch)。标准JSON转义——、
"\n"、"\t"。最终字符串中的真实反斜杠为"\""。"\\\\" - Excel层。单元格中的为真实换行——需搭配
\n让Excel显示换行。可直接在Shell引号的属性中使用(--prop wrapText=true);batch JSON中的--prop value='a\nb'效果相同。若不确定,使用"\n"查看单元格并逐字符对比。officecli get
Other common pitfalls
其他常见陷阱
| Pitfall | Fix |
|---|---|
| All attrs go through |
| Guessing a prop name | |
| Ambiguous — use |
| Drop the |
| |
Unquoted | Quote every path: |
| Sheet name with spaces | Quote full path: |
Year showing as | |
| Modifying a file open in Excel | Close it in Excel first |
| |
| Cached values missing after write | New formulas get cached values when a human opens the file; |
| 陷阱 | 修复方法 |
|---|---|
| 所有属性需通过 |
| 猜测属性名称 | 使用 |
在单元格上使用 | 存在歧义——使用 |
| 去掉 |
| |
zsh/bash中未加引号的 | 为所有路径添加引号: |
| 带空格的工作表名称 | 为完整路径添加引号: |
年份显示为 | 使用 |
| 修改已在Excel中打开的文件 | 先在Excel中关闭该文件 |
| |
| 写入后缺失缓存值 | 人类用户打开文件时,新增公式会获取缓存值; |