OfficeCLI Usage Examples: Creating, Modifying, and Rendering Office Documents Without Installation
OfficeCLI is a single-binary CLI tool that enables you to create, read, modify, and render Word (.docx), Excel (.xlsx), and PowerPoint (.pptx) files through a three-layer architecture—Read (L1), DOM (L2), and Raw XML (L3)—without requiring any Microsoft Office installation or licensing.
The iOfficeAI/OfficeCLI repository provides a self-contained executable that operates across macOS, Linux, and Windows, exposing all functionality through deterministic JSON output suitable for AI agents and CI pipelines. According to the source code in src/officecli/Handlers/Word/WordHandler.cs, the tool implements high-level document operations while maintaining the ability to manipulate underlying XML structures directly when necessary.
Installation and Setup
Install OfficeCLI using the official one-line installer scripts maintained in the repository root.
For macOS and Linux:
curl -fsSL https://raw.githubusercontent.com/iOfficeAI/OfficeCLI/main/install.sh | bash
For Windows PowerShell:
irm https://raw.githubusercontent.com/iOfficeAI/OfficeCLI/main/install.ps1 | iex
The installation registers the binary and optionally configures the OfficeCLI skill for supported AI agents. For Node.js environments, the npm/officecli.js entry point provides a thin SDK that auto-installs the binary and proxies calls, enabling programmatic access from JavaScript or TypeScript projects.
Understanding the Three-Layer Architecture
OfficeCLI organizes commands into three functional layers to balance ease of use with precision control:
| Layer | Purpose | Typical Commands |
|---|---|---|
| L1 – Read | High-level views (text, outline, HTML, PNG, stats, issues) | view ... outline, view ... html, view ... screenshot |
| L2 – DOM | Structured element operations using stable, 1-based element paths | get, query, set, add, remove, move, swap |
| L3 – Raw XML | Direct XML manipulation when L2 operations are insufficient | raw, raw-set, add-part |
All commands support the --json flag for deterministic, machine-readable output, making them ideal for automated workflows.
Creating PowerPoint Presentations
The following examples demonstrate creating a new presentation, adding slides, and inserting styled shapes using L2 DOM operations.
Create an empty .pptx file and add a titled slide:
officecli create deck.pptx
officecli add deck.pptx / --type slide --prop title="Q4 Report" --prop background=1A1A2E
Add a textbox shape with specific formatting:
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
Generating Word Documents with Formatting
Create a new Word document, apply heading styles, and export a visual preview as demonstrated in examples/word/run-formatting.sh.
Initialize the document and add structured content:
officecli create report.docx
officecli add report.docx / --type paragraph \
--prop style=Heading1 --prop text="Annual Sales Summary"
Add a paragraph with run-level formatting (bold, color):
officecli add report.docx / --type paragraph \
--prop text="The total revenue increased by 12% YoY." \
--prop font=Calibri --prop size=12pt --prop color=#003366
Render the document as a PNG screenshot for visual verification:
officecli view report.docx screenshot -o report.png
Managing Excel Spreadsheets and Data
OfficeCLI handles workbook creation, sheet management, and cell-level data extraction with JSON export capabilities.
Create a workbook and populate cells A1 through B3:
officecli create budget.xlsx
officecli add budget.xlsx / --type sheet --prop name="Q1"
officecli set budget.xlsx '/Sheet1!A1' --prop value="Region"
officecli set budget.xlsx '/Sheet1!B1' --prop value="Sales"
officecli set budget.xlsx '/Sheet1!A2' --prop value="EMEA"
officecli set budget.xlsx '/Sheet1!B2' --prop value=123456
officecli set budget.xlsx '/Sheet1!A3' --prop value="APAC"
officecli set budget.xlsx '/Sheet1!B3' --prop value=987654
Export the structured data as JSON for downstream processing:
officecli get budget.xlsx '/Sheet1' --depth 2 --json > sheet.json
HTML Preview and Document Inspection
Convert Office documents to high-fidelity HTML for browser-based review or AI inspection without proprietary software:
officecli view deck.pptx html -o /tmp/deck.html
The built-in rendering engine produces standards-compliant HTML that preserves layout and formatting, accessible immediately in any modern browser.
Batch Operations and Resident Mode
Atomic Batch Updates
Apply multiple mutations in a single atomic transaction using JSON instruction files:
cat <<'JSON' > updates.json
[
{"op":"set","path":"/slide[1]/shape[1]","props":{"text":"Q4 Revenue ↑ 25%"}},
{"op":"set","path":"/slide[2]/shape[1]","props":{"fill":"FF0000"}}
]
JSON
officecli batch deck.pptx --input updates.json --json
Resident Mode for Low-Latency Edits
For workflows requiring rapid successive modifications—such as AI agent loops—Resident mode keeps the document loaded in memory via a pipe server implemented in src/officecli/ResidentServer.cs and src/officecli/ResidentClient.cs.
Open a session, apply mutations, and close:
officecli open report.docx
officecli set report.docx /body/p[2]/r[1] --prop bold=true
officecli set report.docx /body/p[3]/r[1] --prop color=FF0000
officecli close report.docx
Resident mode eliminates the overhead of spawning a new process for each operation, significantly reducing round-trip latency for automated workflows.
AI Integration via MCP Protocol
OfficeCLI exposes all functionality through the Model Context Protocol (MCP) via src/officecli/McpServer.cs, enabling direct integration with AI coding assistants.
Register the MCP server with supported agents:
officecli mcp claude # Registers with Claude Code
officecli mcp cursor # Registers with Cursor
officecli mcp list # Displays registered agents
Once registered, AI agents can invoke OfficeCLI commands over JSON-RPC without requiring shell access, processing the --json output directly to understand document structures and apply modifications.
Repository Examples and Reference Implementations
The examples/ directory contains runnable shell and Python scripts demonstrating specific workflows:
- examples/word/tables.sh – Creating and formatting tables within Word documents
- examples/word/sections.sh – Managing section layouts and page formatting
- examples/word/revisions.sh – Working with track changes and revision marks
- examples/word/textbox.sh – Positioned textbox creation and styling
- examples/word/pie.mmd – Mermaid diagram conversion to Office shapes
These files illustrate the full lifecycle from document creation to complex formatting operations using the L2 DOM API.
Summary
- OfficeCLI operates as a single binary requiring no Microsoft Office installation, supporting
.docx,.xlsx, and.pptxformats across platforms. - The three-layer architecture (L1 Read, L2 DOM, L3 Raw XML) provides both high-level convenience and low-level control over document structures.
- Resident mode (
ResidentServer.cs/ResidentClient.cs) maintains documents in memory for low-latency batch operations ideal for AI workflows. - Built-in MCP server (
McpServer.cs) exposes all functionality via JSON-RPC for seamless AI agent integration. - All commands support
--jsonoutput for deterministic, machine-readable results suitable for CI/CD pipelines and automated processing.
Frequently Asked Questions
Does OfficeCLI require Microsoft Office or licensing?
No. OfficeCLI is a completely standalone binary that implements its own document processing logic in handlers like src/officecli/Handlers/Word/WordHandler.cs. It reads and writes the Office Open XML format directly without calling external Office applications or requiring Windows.
What is the difference between the three architecture layers?
L1 (Read) provides high-level document views such as text extraction, HTML rendering, and screenshot generation. L2 (DOM) offers structured element operations using stable paths (e.g., /slide[1]/shape[2]) for adding, removing, or modifying content. L3 (Raw XML) allows direct manipulation of the underlying document XML when L2 operations do not expose the necessary functionality.
How does Resident mode improve performance?
Resident mode, implemented in src/officecli/ResidentServer.cs, keeps the document loaded in memory and maintains a persistent pipe connection. This eliminates the startup overhead of spawning a new process for each command, reducing operation latency from hundreds of milliseconds to tens of milliseconds—critical for AI agent loops that may apply dozens of sequential edits.
Can OfficeCLI integrate with existing CI/CD pipelines?
Yes. Every command supports the --json flag for machine-readable output, and the tool returns standard exit codes indicating success or failure. The batch operation mode allows atomic application of multiple changes with a single command, making it suitable for automated document generation, template processing, and validation workflows in CI environments.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →