OfficeCLI:面向 AI 代理的 Office 套件,可读写 Microsoft Office 文件
英文标题:🔶 OfficeCLI: Office suite for AI agents to read and edit Microsoft Office files
OfficeCLI 是全球首款面向 AI 代理的开源办公套件,支持无头式创建、读取和修改 Word、Excel 与 PowerPoint 文件。它通过内置 HTML 渲染引擎为 AI 提供视觉反馈,实现“渲染→查看→修正”闭环,大幅降低 AI 操作文档的门槛。该项目以单一二进制分发,无需安装 Office 或额外依赖,可通过一行命令集成到 Claude Code、Cursor 等 AI 编程代理中。丰富的功能集覆盖从批量处理、报表生成到 CI/CD 文档管道的各类自动化场景,对开发者与 AI 应用生态具有重要意义。
6.5 MB
587.9 KB
590.3 KB
597.0 KB
2.8 MB
563.4 KB
中文
OfficeCLI 是全球首款且最佳的面向 AI 代理的 Office 套件。
只需一行代码,即可让任何 AI 代理完全控制 Word、Excel 和 PowerPoint。
开源。单一二进制文件。无需安装 Office。无依赖。随处运行。
🌐 网站: officecli.ai | 💬 社区: Discord
在 AionUi 上使用 OfficeCLI 创建 PPT 的过程
PowerPoint 演示文稿
—
Word 文档
—
Excel 电子表格
以上所有文档均由 AI 代理使用 OfficeCLI 完全生成——无模板、无人工编辑。
面向 AI 代理——一行命令开始使用
将此粘贴到 AI 代理的聊天中——它会读取技能文件并自动安装所有内容:
curl -fsSL https://officecli.ai/SKILL.md
就这样。技能文件会教代理如何安装二进制文件并使用所有命令。
选项 A — 图形界面: 安装 AionUi——一款桌面应用,让你通过自然语言创建和编辑 Office 文档,其底层由 OfficeCLI 驱动。只需描述你的需求,AionUi 会处理其余一切。
选项 B — 命令行: 从 GitHub Releases 下载适用于你平台的二进制文件,然后运行:
将二进制文件复制到 PATH 并将 officecli skill 安装到它检测到的每一个 AI 编程代理中——Claude Code、Cursor、Windsurf、GitHub Copilot 等。
你的代理将立即能够代你创建、读取和编辑 Office 文档,无需额外配置。
面向开发者——30 秒快速体验
1. 安装 (macOS / Linux)
curl -fsSL https://raw.githubusercontent.com/iOfficeAI/OfficeCLI/main/install.sh | bash
Windows (PowerShell): irm https://raw.githubusercontent.com/iOfficeAI/OfficeCLI/main/install.ps1 | iex
2. 创建一个空白的 PowerPoint
officecli create deck.pptx
3. 启动实时预览——浏览器中打开 http://localhost:26315
officecli watch deck.pptx
4. 打开另一个终端,添加一张幻灯片——观察浏览器即时更新
officecli add deck.pptx / --type slide --prop title="Hello, World!"
就这样。你运行的每条 add、set 或 remove 命令都会实时刷新预览。继续试验——浏览器就是你的实时反馈循环。
创建演示文稿并添加内容
officecli create deck.pptx
officecli add deck.pptx / --type slide --prop title="Q4 Report" --prop background=1A1A2E
officecli add deck.pptx '/slide[1]' --type shape
--prop text="Revenue grew 25%" --prop x=2cm --prop y=5cm
--prop font=Arial --prop size=24 --prop color=FFFFFF
以大纲形式查看
officecli view deck.pptx outline
→ Slide 1: Q4 Report
→ Shape 1 [TextBox]: Revenue grew 25%
查看 HTML——无需服务器,在浏览器中打开渲染预览
officecli view deck.pptx html
获取任何元素的结构化 JSON
officecli get deck.pptx '/slide[1]/shape[1]' --json
保存并关闭——将常驻会话刷写到磁盘
officecli close deck.pptx
{ "tag": "shape", "path": "/slide[1]/shape[1]", "attributes": { "name": "TextBox 1", "text": "Revenue grew 25%", "x": "720000", "y": "1800000" } }
过去需要 50 行 Python 和 3 个独立的库:
from pptx import Presentation from pptx.util import Inches, Pt prs = Presentation() slide = prs.slides.add_slide(prs.slide_layouts[0]) title = slide.shapes.title title.text = "Q4 Report"
... 45 more lines ...
prs.save('deck.pptx')
现在只需一条命令:
officecli add deck.pptx / --type slide --prop title="Q4 Report"
OfficeCLI 的功能:
- 创建文档——从零开始,空白或带内容
- 读取文本、结构、样式、公式——纯文本或结构化 JSON
- 分析格式问题、样式不一致性和结构性问题
- 修改任何元素——文本、字体、颜色、布局、公式、图表、图像
- 重组内容——添加、删除、移动、跨文档复制元素
| 格式 | 读取 | 修改 | 创建 |
|---|---|---|---|
| Word (.docx) | ✅ | ✅ | ✅ |
| Excel (.xlsx) | ✅ | ✅ | ✅ |
| PowerPoint (.pptx) | ✅ | ✅ | ✅ |
Word — 完整的 i18n 与 RTL 支持(每种脚本字体槽、每种脚本 BCP-47 语言标签 lang.latin/ea/cs、复杂脚本粗体/斜体/大小、direction=rtl 贯穿段落/运行/节/表/样式/页眉/页脚/文档默认值、rtlGutter + pgBorders 简写、针对印地语/阿拉伯语/泰语/CJK 的本地化页码;create --locale ar-SA 自动启用 RTL)、段落(framePr、制表符简写、字符缩进)、文本运行(underline.color,position 半磅单位)、表格(虚拟列操作 添加/删除/移动/复制自、hMerge)、样式、文本框 / 形状(旋转、verticalText eaVert/vert270、渐变、阴影、透明度)、页眉/页脚、图像(PNG/JPG/GIF/SVG)、公式(LaTeX 输入)、图表(mermaid → 原生可编辑形状,或任意 mermaid 类型输出为全保真 PNG)、批注、脚注、水印、书签、目录、图表(Graph)、超链接、节、表单域、内容控件 (SDT)、域(22 个零参数类型 + MERGEFIELD / REF / PAGEREF / SEQ / STYLEREF / DOCPROPERTY / IF)、OLE 对象、修订 / 修订追踪(revision.type=ins\|del\|format\|moveFrom\|moveTo + revision.action=accept\|reject,按目标 /revision[@author=Alice] 选择器,追踪式查找与替换)、页面背景颜色、文档属性
Excel — 单元格(添加时拼音指南 / 振假名,删除时 Excel 界面式 --shift left\|up / 添加时 shift=right\|down)、公式(350+ 内置函数自动求值,溢出动态数组自动前缀 _xlfn.,财务/债券与统计函数族,OFFSET/INDIRECT,定义名称公式体在解析时内联,插入行列时公式引用重写)、工作表(可见/隐藏/深度隐藏、打印边距、printTitleRows/Cols、RTL sheetView、级联感知的工作表重命名、打开时空单元格膨胀过滤)、布尔 and/or 选择器(row[Salary>5000 and Region=EMEA])、表格、排序(工作表/区域,多关键字,侧车感知)、条件格式、图表(包括箱须图、帕累托图自动排序 + 累积百分比,对数轴)、数据透视表(多字段,日期分组,showDataAs,排序,总计,分类汇总,紧凑/大纲/表格布局,重复项标签,空行,计算字段,持久 labelFilter / topN / fillDownLabels,缓存写时复制 + 跨透视表共享)、切片器、命名区域、数据验证、图像(PNG/JPG/GIF/SVG 双表示降级回退)、迷你图、批注(RTL)、自动筛选、形状、OLE 对象、CSV/TSV 导入、$Sheet:A1 单元格寻址
PowerPoint — 幻灯片(页眉/页脚/日期/幻灯片编号开关、隐藏)、形状(图案填充、模糊效果、超链接提示 + 幻灯片跳转链接、文本运行上的高亮颜色、slideMaster/slideLayout 类型化 添加/设置/删除、箭头别名、effective.X + effective.X.src)、图像(PNG/JPG/GIF/SVG,填充模式:拉伸/包含/覆盖/平铺,亮度/对比度/发光/阴影,旋转,链接 + 提示)、表格(内置 PowerPoint 样式目录,虚拟 /col[C] get + 交换/复制自,行/列移动/复制自,填充/背景别名)、图表(复合饼图、复合条饼图,按属性设置轴线/网格线,系列按主题调色板添加/删除,anchor=x,y,w,h 简写)、动画(15 种强调 + 16 种退出模板预设,多效果链,运动路径预设,重复/重新开始/自动翻转,图表动画 + chartBuild)、过渡(变形 + p14 + 12 个 p15 PowerPoint 2013+ 预设)、3D 模型 (.glb)(组合 rotation=ax,ay,az)、幻灯片缩放、公式(LaTeX 输入)、图表(Diagram)(mermaid 流程图 / 序列图 → 原生可编辑形状,或任意 mermaid 类型输出为全保真 PNG)、主题、连接符(@name= 选择器指定起始/终点)、视频/音频(循环,自动播放)、组合(链接 + 提示;获取/查询/添加/删除均下沉至组内)、备注(RTL,语言)、批注(RTL,旧版与现代 p188 线程化往返)、SmartArt(通过 add-part + raw-set 往返)、OLE 对象、占位符(按 phType 添加/设置)
面向开发者:
- 从数据库或 API 自动化生成报表
- 批量处理文档(批量查找/替换、样式更新)
- 在 CI/CD 环境中构建文档流水线(从测试结果生成文档)
- 在 Docker/容器化环境中进行无头 Office 自动化
面向 AI 代理:
- 根据用户提示生成演示文稿(见上方示例)
- 从文档中提取结构化数据到 JSON
- 在交付前验证和检查文档质量
面向团队:
- 克隆文档模板并填充数据
- CI/CD 流水线中的自动文档验证
以单个自包含二进制文件交付。.NET 运行时已内嵌——无需安装任何东西,无需管理运行时。
一行命令安装:
macOS / Linux
curl -fsSL https://raw.githubusercontent.com/iOfficeAI/OfficeCLI/main/install.sh | bash
Windows (PowerShell)
irm https://raw.githubusercontent.com/iOfficeAI/OfficeCLI/ma
English / 原文
OfficeCLI is the world's first and the best Office suite designed for AI agents.
Give any AI agent full control over Word, Excel, and PowerPoint — in one line of code.
Open-source. Single binary. No Office installation. No dependencies. Works everywhere.
OfficeCLI's built-in HTML rendering engine reproduces documents with high fidelity — and that's what gives AI eyes. It renders .docx / .xlsx / .pptx to HTML or PNG, closing the render → look → fix loop.
🌐 Website: officecli.ai | 💬 Community: Discord
PPT creation process using OfficeCLI onAionUi
PowerPoint Presentations
—
Word Documents
—
Excel Spreadsheets
All documents above were created entirely by AI agents using OfficeCLI — no templates, no manual editing.
For AI Agents — Get Started in One Line
Paste this into your AI agent's chat — it will read the skill file and install everything automatically:
curl -fsSL https://officecli.ai/SKILL.md
That's it. The skill file teaches the agent how to install the binary and use all commands.
Option A — GUI: Install AionUi — a desktop app that lets you create and edit Office documents through natural language, powered by OfficeCLI under the hood. Just describe what you want, and AionUi handles the rest.
Option B — CLI: Download the binary for your platform from GitHub Releases, then run:
This copies the binary to your PATH and installs the officecli skill into every AI coding agent it detects — Claude Code, Cursor, Windsurf, GitHub Copilot, and more. Your agent can immediately create, read, and edit Office documents on your behalf, no extra configuration needed.
For Developers — See It Live in 30 Seconds
# 1. Install (macOS / Linux)
curl -fsSL https://raw.githubusercontent.com/iOfficeAI/OfficeCLI/main/install.sh | bash
# Windows (PowerShell): irm https://raw.githubusercontent.com/iOfficeAI/OfficeCLI/main/install.ps1 | iex
# 2. Create a blank PowerPoint
officecli create deck.pptx
# 3. Start live preview — opens http://localhost:26315 in your browser
officecli watch deck.pptx
# 4. Open another terminal, add a slide — watch the browser update instantly
officecli add deck.pptx / --type slide --prop title="Hello, World!"
That's it. Every add, set, or remove command you run will refresh the preview in real time. Keep experimenting — the browser is your live feedback loop.
# Create a presentation and add content
officecli create deck.pptx
officecli add deck.pptx / --type slide --prop title="Q4 Report" --prop background=1A1A2E
officecli add deck.pptx '/slide[1]' --type shape \
--prop text="Revenue grew 25%" --prop x=2cm --prop y=5cm \
--prop font=Arial --prop size=24 --prop color=FFFFFF
# View as outline
officecli view deck.pptx outline
# → Slide 1: Q4 Report
# → Shape 1 [TextBox]: Revenue grew 25%
# View as HTML — opens a rendered preview in your browser, no server needed
officecli view deck.pptx html
# Get structured JSON for any element
officecli get deck.pptx '/slide[1]/shape[1]' --json
# Save and close — flushes the resident session to disk
officecli close deck.pptx
{
"tag": "shape",
"path": "/slide[1]/shape[1]",
"attributes": {
"name": "TextBox 1",
"text": "Revenue grew 25%",
"x": "720000",
"y": "1800000"
}
}
What used to take 50 lines of Python and 3 separate libraries:
from pptx import Presentation
from pptx.util import Inches, Pt
prs = Presentation()
slide = prs.slides.add_slide(prs.slide_layouts[0])
title = slide.shapes.title
title.text = "Q4 Report"
# ... 45 more lines ...
prs.save('deck.pptx')
Now takes one command:
officecli add deck.pptx / --type slide --prop title="Q4 Report"
What OfficeCLI can do:
- Create documents from scratch -- blank or with content
- Read text, structure, styles, formulas -- in plain text or structured JSON
- Analyze formatting issues, style inconsistencies, and structural problems
- Modify any element -- text, fonts, colors, layout, formulas, charts, images
- Reorganize content -- add, remove, move, copy elements across documents
| Format | Read | Modify | Create |
|---|---|---|---|
| Word (.docx) | ✅ | ✅ | ✅ |
| Excel (.xlsx) | ✅ | ✅ | ✅ |
| PowerPoint (.pptx) | ✅ | ✅ | ✅ |
Word — full i18n & RTL support (per-script font slots, per-script BCP-47 lang tags lang.latin/ea/cs, complex-script bold/italic/size, direction=rtl cascading through paragraph/run/section/table/style/header/footer/docDefaults, rtlGutter + pgBorders shorthand, locale-aware page numbering for Hindi/Arabic/Thai/CJK; create --locale ar-SA auto-enables RTL), paragraphs (framePr, tabs shorthand, char-based indents), runs (underline.color, position half-pts), tables (virtual column ops add/remove/move/copyfrom, hMerge), styles, textbox / shape (rotation, verticalText eaVert/vert270, gradient, shadow, opacity), headers/footers, images (PNG/JPG/GIF/SVG), equations (LaTeX input), diagrams (mermaid → native editable shapes, or any mermaid type as a full-fidelity PNG), comments, footnotes, watermarks, bookmarks, TOC, charts, hyperlinks, sections, form fields, content controls (SDT), fields (22 zero-param types + MERGEFIELD / REF / PAGEREF / SEQ / STYLEREF / DOCPROPERTY / IF), OLE objects, revisions / tracked changes (revision.type=ins\|del\|format\|moveFrom\|moveTo + revision.action=accept\|reject, per-target /revision[@author=Alice] selector, tracked Find&Replace), page background color, document properties
Excel — cells (phonetic guide / furigana on add, Excel-UI --shift left\|up on remove / shift=right\|down on add), formulas (350+ built-in functions with auto-evaluation, spilling dynamic arrays with _xlfn. auto-prefix, financial / bond and statistical families, OFFSET/INDIRECT, defined-name formula bodies inlined at parse, formula-ref rewrite on row/col insert), sheets (visible/hidden/veryHidden, print margins, printTitleRows/Cols, RTL sheetView, cascade-aware sheet rename, empty-cell bloat filter on open), boolean and/or selectors (row[Salary>5000 and Region=EMEA]), tables, sort (sheet / range, multi-key, sidecar-aware), conditional formatting, charts (including box-whisker, pareto with auto-sort + cumulative-%, log axis), pivot tables (multi-field, date grouping, showDataAs, sort, grandTotals, subtotals, compact/outline/tabular layout, repeat item labels, blank rows, calculated fields, persistent labelFilter / topN / fillDownLabels, cache CoW + cross-pivot sharing), slicers, named ranges, data validation, images (PNG/JPG/GIF/SVG with dual-representation fallback), sparklines, comments (RTL), autofilter, shapes, OLE objects, CSV/TSV import, $Sheet:A1 cell addressing
PowerPoint — slides (header/footer/date/slidenum toggles, hidden), shapes (pattern fill, blur effect, hyperlink tooltip + slide-jump links, highlight color on runs, slideMaster/slideLayout typed add/set/remove, arrow alias, effective.X + effective.X.src), images (PNG/JPG/GIF/SVG, fill modes: stretch/contain/cover/tile, brightness/contrast/glow/shadow, rotation, link + tooltip), tables (built-in PowerPoint style catalogue, virtual /col[C] get + swap/copyFrom, row/col Move/CopyFrom, fill/background alias), charts (pieOfPie, barOfPie, per-attr axisLine/gridline setters, series add/remove with theme palette, anchor=x,y,w,h shorthand), animations (15 emphasis + 16 exit template-backed presets, multi-effect chains, motion-path presets, repeat/restart/autoReverse, chart animations + chartBuild), transitions (morph + p14 + 12 p15 PowerPoint 2013+ presets), 3D models (.glb) (combined rotation=ax,ay,az), slide zoom, equations (LaTeX input), diagrams (mermaid flowchart / sequence → native editable shapes, or any mermaid type as a full-fidelity PNG), themes, connectors (@name= selector for from/to), video/audio (loop, autoStart), groups (link + tooltip; Get/Query/Add/Remove all descend into groups), notes (RTL, lang), comments (RTL, legacy + modern p188 threaded round-trip), SmartArt (round-trip via add-part + raw-set), OLE objects, placeholders (add/set by phType)
For Developers:
- Automate report generation from databases or APIs
- Batch-process documents (bulk find/replace, style updates)
- Build document pipelines in CI/CD environments (generate docs from test results)
- Headless Office automation in Docker/containerized environments
For AI Agents:
- Generate presentations from user prompts (see examples above)
- Extract structured data from documents to JSON
- Validate and check document quality before delivery
For Teams:
- Clone document templates and populate with data
- Automated document validation in CI/CD pipelines
Ships as a single self-contained binary. The .NET runtime is embedded -- nothing to install, no runtime to manage.
One-line install:
# macOS / Linux
curl -fsSL https://raw.githubusercontent.com/iOfficeAI/OfficeCLI/main/install.sh | bash
# Windows (PowerShell)
irm https://raw.githubusercontent.com/iOfficeAI/OfficeCLI/main/install.ps1 | iex
Or download manually from GitHub Releases:
| Platform | Binary |
|---|---|
| macOS Apple Silicon | officecli-mac-arm64 |
| macOS Intel | officecli-mac-x64 |
| Linux x64 | officecli-linux-x64 |
| Linux ARM64 | officecli-linux-arm64 |
| Windows x64 | officecli-win-x64.exe |
| Windows ARM64 | officecli-win-arm64.exe |
Verify installation: officecli --version
Or self-install from a downloaded binary (or run bareofficecli to auto-install):
officecli install # explicit
officecli # bare invocation also triggers install
Updates are checked automatically in the background. Disable with officecli config autoUpdate false or skip per-invocation with OFFICECLI_SKIP_UPDATE=1. Configuration lives under ~/.officecli/config.json.
Built-in Engines & Generation Primitives
OfficeCLI is self-contained. The capabilities below ship inside the binary — no Office required.
Rendering engine — high-fidelity, built-in
OfficeCLI's keystone: a from-scratch, high-fidelity HTML rendering engine that lets an AI agent see the rendered document instead of guessing from the DOM. It covers shapes, charts (trendlines, error bars, waterfall, candlestick, sparklines), equations (OMML → MathJax-compatible), 3D .glb models via Three.js, morph transitions, slide zoom, and shape effects. Per-page PNG screenshots are produced by piping the rendered HTML through a headless browser. Three modes:
-
view html— standalone HTML file, assets inlined. Open in any browser. -
view screenshot— per-page PNG, ready for multimodal agents to read. -
watch— local HTTP server with auto-refreshing preview; everyadd/set/removeupdates the browser instantly. Excel watch supports inline cell editing and drag-to-reposition charts.officecli view deck.pptx html -o /tmp/deck.html officecli view deck.pptx screenshot -o /tmp/deck.png # add --page 1-N for more slides officecli watch deck.pptx # http://localhost:26315
Without visualization, an agent generating slides is flying blind — it can read the DOM but can't tell if the title overflows or two shapes overlap. Because rendering is built into the binary, the render → look → fix loop works in CI, in Docker, on a server with no display — anywhere the binary runs.
350+ built-in Excel functions evaluated automatically on write — write =SUM(A1:A2), get the cell, the value is already there. No round-trip through Office to recalc. Covers spilling dynamic arrays (FILTER / SORT / UNIQUE / SEQUENCE / LET / LAMBDA / MAP), VLOOKUP / XLOOKUP / INDEX / MATCH, financial & bond math (XIRR / PRICE / YIELD / DURATION / COUPNUM), statistical distributions, tests & regression (NORM.DIST / T.TEST / LINEST), and date & text functions.
Plus native OOXML pivot tables from a source range with one command — multi-field rows/cols/filters, 10 aggregations, showDataAs modes, date grouping, calculated fields, top-N, layouts. Pivot cache + definition are written to OOXML, so Excel opens the file with the aggregation already populated:
officecli add sales.xlsx '/Sheet1' --type pivottable \
--prop source='Data!A1:E10000' --prop rows='Region,Category' \
--prop cols=Quarter --prop values='Revenue:sum,Units:avg' \
--prop showDataAs=percentOfTotal
Template merge — generate once, fill many
merge replaces {{key}} placeholders in any .docx / .xlsx / .pptx with JSON data — across paragraphs, table cells, shapes, headers, footers, and chart titles. Agent designs the layout once (expensive); production code fills it N times (cheap, deterministic, zero token cost). Avoids the failure mode where an agent regenerates each report from scratch and produces N inconsistent layouts.
officecli merge invoice-template.docx out-001.docx '{"client":"Acme","total":"$5,200"}'
officecli merge q4-template.pptx q4-acme.pptx data.json
Round-trip dump — learn from existing docs
dump serializes any .docx, .pptx, or .xlsx — whole document or any subtree (a single paragraph, table, slide, worksheet, the styles part, numbering, theme, or settings) — into a replayable batch JSON; batch replays it. Given a sample the user wants to imitate, an agent reads the structured spec instead of raw OOXML XML, mutates, and replays. Bridges "I have an existing template" and "generate me 100 variations."
officecli dump existing.docx -o blueprint.json # whole document
officecli dump existing.docx /body/tbl[1] -o table.json # any subtree
officecli dump existing.xlsx /Sheet1 -o sheet.json # a single worksheet
officecli batch new.docx --input blueprint.json
For multi-step workflows, resident mode keeps the document in memory. Batch mode applies multiple operations in a single pass.
# Resident mode — near-zero latency via named pipes
officecli open report.docx
officecli set report.docx /body/p[1]/r[1] --prop bold=true
officecli set report.docx /body/p[2]/r[1] --prop color=FF0000
officecli close report.docx
# Batch mode — multi-command execution (continues on error by default; --stop-on-error to abort)
echo '[{"command":"set","path":"/slide[1]/shape[1]","props":{"text":"Hello"}},
{"command":"set","path":"/slide[1]/shape[2]","props":{"fill":"FF0000"}}]' \
| officecli batch deck.pptx --json
# Inline batch with --commands (no stdin needed)
officecli batch deck.pptx --commands '[{"op":"set","path":"/slide[1]/shape[1]","props":{"text":"Hi"}}]'
# Abort on the first failing command (default is continue-on-error)
officecli batch deck.pptx --input updates.json --stop-on-error --json
Reading the file with another tool? Flush to disk first. officecli's own reads (
get/query/view) always see your latest edits, so within officecli you never need to save. But a live resident defers the disk write, so before a non‑officecli program reads the file — python‑docx/openpyxl, Microsoft Word, a renderer, delivery/upload — flush it:officecli set report.docx /body/p[1] --prop bold=true officecli save report.docx # flush, keep the resident warm (or `close` to flush + release) python my_reader.py report.docx # now sees the editA live resident also auto‑flushes shortly after going idle (adaptive 2–10s, scaled to the document's measured save cost). For a pipeline where another program reads after every command, set
OFFICECLI_RESIDENT_FLUSH=each— every mutation is on disk before the command returns, while the resident stays warm. Full flush model (each/auto/fixed/off, save / close, env tuning): wiki → open / close.
Start simple, go deep only when needed.
| Layer | Purpose | Commands |
|---|---|---|
| L1: Read | Semantic views of content | view (text, annotated, outline, stats, issues, html, svg, screenshot) |
| L2: DOM | Structured element operations | get, query, set, add, remove, move, swap |
| L3: Raw XML | Direct XPath access — universal fallback | raw, raw-set, add-part, validate |
# L1 — high-level views
officecli view report.docx annotated
officecli view budget.xlsx text --cols A,B,C --max-lines 50
# L2 — element-level operations
officecli query report.docx "run:contains(TODO)"
officecli add budget.xlsx / --type sheet --prop name="Q2 Report"
officecli move report.docx /body/p[5] --to /body --index 1
# L3 — raw XML when L2 isn't enough
officecli raw deck.pptx '/slide[1]'
officecli raw-set report.docx document \
--xpath "//w:p[1]" --action append \
--xml '<w:r><w:t>Injected text</w:t></w:r>'
Built-in MCP server — register with one command:
officecli mcp claude # Claude Code
officecli mcp cursor # Cursor
officecli mcp vscode # VS Code / Copilot
officecli mcp lmstudio # LM Studio
officecli mcp list # Check registration status
Exposes all document operations as tools over JSON-RPC — no shell access needed.
Get OfficeCLI working with your AI agent in two steps:
- Install the binary -- one command (see Installation)
- Done. OfficeCLI automatically detects your AI tools (Claude Code, GitHub Copilot, Codex) by checking known config directories and installs its skill file. Your agent can immediately create, read, and modify any Office document.
Manual setup (optional)
If auto-install doesn't cover your setup, you can install the skill file manually:
Feed SKILL.md to your agent directly:
curl -fsSL https://officecli.ai/SKILL.md
Install as a local skill for Claude Code:
curl -fsSL https://officecli.ai/SKILL.md -o ~/.claude/skills/officecli.md
Other agents: Include the contents of SKILL.md in your agent's system prompt or tool description.
Why your agent will thrive on OfficeCLI
- Deterministic JSON output — every command supports
--jsonwith consistent schemas. No regex parsing, no scraping stdout. - Path-based addressing — every element has a stable path (
/slide[1]/shape[2]). Agents navigate documents without understanding XML namespaces. (OfficeCLI syntax: 1-based indexing, element local names — not XPath.) - Progressive complexity (L1 → L2 → L3) — agents start with read-only views, escalate to DOM ops, fall back to raw XML only when needed. Minimizes token usage.
- Self-healing workflow —
validate,view issues, and the structured error codes (not_found,invalid_value,unsupported_property) return suggestions and valid ranges. Agents self-correct without human intervention. - Built-in agent-friendly rendering engine —
view html/view screenshot/watchemit HTML and PNG natively. No Office required. Agents can see their output and fix layout issues, even inside CI / Docker / headless environments. - Built-in formula & pivot engine — 350+ Excel functions auto-evaluated on write (incl. spilling dynamic arrays, financial / bond and statistical families); native OOXML pivot tables from a source range with one command. Agents read computed values and shipped aggregations immediately, without round-tripping through Office.
- Template merge — agent designs the layout once, downstream code fills
{{key}}placeholders N times. Avoids burning tokens regenerating every report from scratch. - Round-trip dump —
dumpturns any.docx,.pptx, or.xlsxinto replayable batch JSON. Agents learn from human-authored samples by reading a structured spec, not raw OOXML XML. - Built-in help — when unsure about property names or value formats, the agent runs
officecli <format> set <element>instead of guessing. - Auto-install — OfficeCLI detects your AI tooling (Claude Code, Cursor, VS Code, …) and configures itself. No manual skill-file setup.
Don't guess property names — drill into the help:
officecli pptx set # All settable elements and properties
officecli pptx set shape # Detail for one element type
officecli pptx set shape.fill # One property: format and examples
officecli docx query # Selector reference: attributes, :contains, :has(), etc.
Run officecli --help for the full overview.
All commands support --json. The general response shapes:
Single element (get --json):
{"tag": "shape", "path": "/slide[1]/shape[1]", "attributes": {"name": "TextBox 1", "text": "Hello"}}
List of elements (query --json):
[
{"tag": "paragraph", "path": "/body/p[1]", "attributes": {"style": "Heading1", "text": "Title"}},
{"tag": "paragraph", "path": "/body/p[5]", "attributes": {"style": "Heading1", "text": "Summary"}}
]
Errors return a non-zero exit code with a structured error object including error code, suggestion, and valid values when available:
{
"success": false,
"error": {
"error": "Slide 50 not found (total: 8)",
"code": "not_found",
"suggestion": "Valid Slide index range: 1-8"
}
}
Error codes: not_found, invalid_value, unsupported_property, invalid_path, unsupported_type, missing_property, file_not_found, file_locked, invalid_selector. Property names are auto-corrected -- misspelling a property returns a suggestion with the closest match.
Error Recovery -- Agents self-correct by inspecting available elements:
# Agent tries an invalid path
officecli get report.docx /body/p[99] --json
# Returns: {"success": false, "error": {"error": "...", "code": "not_found", "suggestion": "..."}}
# Agent self-corrects by checking available elements
officecli get report.docx /body --depth 1 --json
# Returns the list of available children, agent picks the right path
Mutation confirmations (set, add, remove, move, create with --json):
{"success": true, "path": "/slide[1]/shape[1]"}
See officecli --help for full details on exit codes and error formats.
| OfficeCLI | Microsoft Office | LibreOffice | python-docx / openpyxl
---|---|---|---|---
Open source & free | ✓ (Apache 2.0) | ✗ (paid license) | ✓ | ✓
AI-native CLI + JSON | ✓ | ✗ | ✗ | ✗
Zero install (single binary) | ✓ | ✗ | ✗ | ✗ (Python + pip)
Call from any language | ✓ (CLI) | ✗ (COM/Add-in) | ✗ (UNO API) | Python only
Path-based element access | ✓ | ✗ | ✗ | ✗
Raw XML fallback | ✓ | ✗ | ✗ | Partial
Built-in agent-friendly rendering engine | ✓ | ✗ | ✗ | ✗
Headless HTML/PNG output | ✓ | ✗ | Partial | ✗
Template merge ({{key}}) across formats | ✓ | ✗ | ✗ | ✗
Round-trip dump → batch JSON | ✓ | ✗ | ✗ | ✗
Live preview (auto-refresh on edit) | ✓ | ✗ | ✗ | ✗
Headless / CI | ✓ | ✗ | Partial | ✓
Cross-platform | ✓ | Windows/Mac | ✓ | ✓
Word + Excel + PowerPoint | ✓ | ✓ | ✓ | Separate libs
Command | Description
---|---
create | Create a blank .docx, .xlsx, or .pptx (type from extension)
view | View content (modes: outline, text, annotated, stats (--page-count), issues, html, svg, screenshot, pdf (via exporter plugin), forms (via format-handler plugin)). docx supports --render auto|native|html.
load_skill | Print embedded SKILL.md content for a specialized skill (no install)
get | Get element and children (--depth N, --json)
query | CSS-like query with boolean and/or, row-by-column-name (row[Salary>5000]), --find flag
set | Modify element properties; accepts selectors and Excel-native paths (parity with get/query), --find/--replace flags
add | Add element (or clone with --from <path>)
remove | Remove an element
move | Move element (--to <parent>, --index N, --after <path>, --before <path>)
swap | Swap two elements
validate | Validate against OpenXML schema
view <file> issues | Enumerate document issues (text overflow, missing alt text, formula errors, ...)
batch | Multiple operations applied in a single pass (stdin, --input, or --commands; continues on error by default, --stop-on-error to abort)
dump | Serialize a .docx, .pptx, or .xlsx into a replayable batch JSON (round-trip via batch); accepts a subtree path
refresh | Recalculate TOC page numbers / PAGE / cross-references (.docx; Word backend on Windows, headless-HTML fallback)
plugins | List / inspect / lint installed plugins (extend to .doc, .hwpx, .pdf export via dump-reader / exporter / format-handler kinds)
merge | Template merge — replace {{key}} placeholders with JSON data
watch | Live HTML preview in browser with auto-refresh
mcp | Start MCP server for AI tool integration
raw | View raw XML of a document part
raw-set | Modify raw XML via XPath
add-part | Add a new document part (header, chart, etc.)
open | Start resident mode (keep document in memory)
close | Save and close resident mode
install | Install binary + skills + MCP (all, claude, cursor, etc.)
config | Get or set configuration
<format> <command> | Built-in help (e.g. officecli pptx set shape)
End-to-End Workflow Example
A typical self-healing agent workflow: create a presentation, populate it, verify, and fix issues -- all without human intervention.
# 1. Create
officecli create report.pptx
# 2. Add content
officecli add report.pptx / --type slide --prop title="Q4 Results"
officecli add report.pptx '/slide[1]' --type shape \
--prop text="Revenue: $4.2M" --prop x=2cm --prop y=5cm --prop size=28
officecli add report.pptx / --type slide --prop title="Details"
officecli add report.pptx '/slide[2]' --type shape \
--prop text="Growth driven by new markets" --prop x=2cm --prop y=5cm
# 3. Verify
officecli view report.pptx outline
officecli validate report.pptx
# 4. Fix any issues found
officecli view report.pptx issues --json
# Address issues based on output, e.g.:
officecli set report.pptx '/slide[1]/shape[1]' --prop font=Arial
All dimension and color properties accept flexible input formats:
| Type | Accepted formats | Examples |
|---|---|---|
| Dimensions | cm, in, pt, px, or raw EMU | 2cm, 1in, 72pt, 96px, 914400 |
| Colors | Hex, named, RGB, theme | #FF0000, FF0000, red, rgb(255,0,0), accent1 |
| Font sizes | Bare number or pt-suffixed | 14, 14pt, 10.5pt |
| Spacing | pt, cm, in, or multiplier | 12pt, 0.5cm, 1.5x, 150% |
# Replace all Heading1 text in a Word doc
officecli query report.docx "paragraph[style=Heading1]" --json | ...
officecli set report.docx /body/p[1]/r[1] --prop text="New Title"
# Export all slide content as JSON
officecli get deck.pptx / --depth 2 --json
# Bulk-update Excel cells
officecli batch budget.xlsx --input updates.json --json
# Import CSV data into an Excel sheet
officecli add budget.xlsx / --type sheet --prop name="Q1 Data" --prop csv=sales.csv
# Template merge for batch reports
officecli merge invoice-template.docx invoice-001.docx '{"client":"Acme","total":"$5,200"}'
# Check document quality before delivery
officecli validate report.docx && officecli view report.docx issues --json
From Python or Node.js — install one of the thin resident-pipe SDKs (no per-call process spawn):
# Python — `pip install officecli-sdk`
from officecli import Doc
with Doc("deck.pptx") as d:
d.add("/", type="slide", title="Q4 Report")
print(d.get("/slide[1]"))
// Node.js — `npm install @officecli/sdk`
import { Doc } from "@officecli/sdk";
await using d = await Doc.open("deck.pptx");
await d.add("/", { type: "slide", title: "Q4 Report" });
console.log(await d.get("/slide[1]"));
Both SDKs auto-provision the native CLI when missing (mirror-first, Windows-capable) and announce the install rather than doing it silently.
Or wrap subprocess directly, one-shot:
import json, subprocess
def cli(*args):
return json.loads(subprocess.check_output(["officecli", *args, "--json"], text=True))
cli("create", "deck.pptx")
The Wiki has detailed guides for every command, element type, and property:
Requires .NET 10 SDK for compilation only. The output is a self-contained, native binary -- .NET is embedded in the binary and is not needed at runtime.
Bug reports and contributions are welcome on GitHub Issues.
If you find OfficeCLI useful, please give it a star on GitHub — it helps others discover the project.
