OfficeCLI Usage Examples: Creating, Modifying, and Viewing Office Documents Without Installation
OfficeCLI provides comprehensive usage examples for creating, reading, and modifying Word (.docx), Excel (.xlsx), and PowerPoint (.pptx) files through a single binary that requires no Office installation.
The iOfficeAI/OfficeCLI repository demonstrates practical implementations of its three-layer architecture (L1 Read, L2 DOM, L3 Raw XML) through runnable shell scripts and code snippets. These examples showcase everything from simple document creation to batch operations and AI agent integrations via the Model Context Protocol (MCP).
Installation and Quick Start
Before running any OfficeCLI usage examples, install the self-contained binary using the official one-liner script.
# 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
This command installs the binary and registers the OfficeCLI skill for supported AI agents, enabling immediate execution of all documented commands.
Creating and Modifying PowerPoint Presentations
Creating a New Deck with Styled Slides
The following example demonstrates the create and add commands to build a presentation programmatically. As implemented in the core handlers, these commands support stable 1-based element paths for reliable DOM manipulation.
# Create an empty .pptx file
officecli create deck.pptx
# Add the first slide with a title
officecli add deck.pptx / --type slide --prop title="Q4 Report" --prop background=1A1A2E
# Add a textbox shape to the slide
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 HTML Previews
OfficeCLI can render presentations to high-fidelity HTML for instant browser preview without external dependencies.
officecli view deck.pptx html -o /tmp/deck.html
This L1 Read layer operation produces deterministic output suitable for CI pipelines or automated documentation workflows.
Word Document Manipulation Examples
Adding Structured Content and Exporting to Image
The WordHandler.cs file (located at src/officecli/Handlers/Word/WordHandler.cs) implements the core logic for paragraph creation and formatting. The following example creates a styled document and renders it as PNG screenshots.
# Start a new .docx
officecli create report.docx
# Add a heading paragraph
officecli add report.docx / --type paragraph \
--prop style=Heading1 --prop text="Annual Sales Summary"
# Add a normal paragraph with custom font and 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 whole document as PNG pages
officecli view report.docx screenshot -o report.png
Working with Tables and Sections
The repository's examples/word/ directory contains specialized scripts for complex operations:
tables.sh: Demonstrates Excel-style table creation within Word documentssections.sh: Shows section layout manipulation and page formattingrun-formatting.sh: Illustrates run-level formatting (bold, color, font changes) using the L2 DOM layerrevisions.sh: Implements revision tracking commands for collaborative editing
Excel Spreadsheet Operations
OfficeCLI handles Excel files using the same three-layer approach. This example creates a workbook, populates cells with typed data, and exports structured JSON.
# Create a workbook and a sheet
officecli create budget.xlsx
officecli add budget.xlsx / --type sheet --prop name="Q1"
# Populate cells A1:B3 with values
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 sheet as JSON for downstream processing
officecli get budget.xlsx '/Sheet1' --depth 2 --json > sheet.json
The --json flag ensures deterministic, machine-readable output perfect for data pipelines.
Batch Operations and Automation
Atomic Multi-Step Updates
For scenarios requiring multiple modifications, the batch command accepts a JSON array of operations and applies them atomically.
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
This approach minimizes file I/O and ensures consistency across complex document transformations.
Resident Mode for Low-Latency Editing
When performing multiple sequential operations—such as in AI agent loops or interactive editing sessions—Resident Mode keeps the document in memory to eliminate binary spawn overhead.
# Open a document in resident mode
officecli open report.docx
# Apply several mutations quickly
officecli set report.docx /body/p[2]/r[1] --prop bold=true
officecli set report.docx /body/p[3]/r[1] --prop color=FF0000
# Flush changes to disk and close the resident session
officecli close report.docx
According to the iOfficeAI/OfficeCLI source code, this functionality is implemented in src/officecli/ResidentServer.cs (server-side pipe handling) and src/officecli/ResidentClient.cs (client communication), creating a persistent document session that drastically reduces round-trip latency.
AI Integration via MCP Server
OfficeCLI exposes all commands as JSON-RPC tools through a built-in MCP (Model Context Protocol) server, enabling direct integration with AI coding assistants.
officecli mcp claude # registers with Claude Code
officecli mcp cursor # registers with Cursor
officecli mcp list # shows registered agents
The McpServer.cs file (src/officecli/McpServer.cs) implements this protocol, allowing agents to manipulate Office documents without direct shell access or file system permissions.
Node.js SDK and Language Bindings
For JavaScript/TypeScript projects, OfficeCLI provides an npm package that auto-installs the binary and proxies calls. The entry point at npm/officecli.js handles binary management transparently.
// Example usage via the Node SDK
const officecli = require('officecli');
// All commands return promises with structured results
await officecli.create('document.docx');
await officecli.add('document.docx', '/', {
type: 'paragraph',
props: { text: 'Automated content', style: 'Normal' }
});
Python equivalents are available in the examples/word/ directory, demonstrating cross-language consistency.
Summary
- OfficeCLI requires no Microsoft Office installation and runs as a single binary on macOS, Linux, and Windows.
- The three-layer architecture (L1 Read, L2 DOM, L3 Raw XML) provides both high-level convenience and low-level control via commands like
get,set,add, andraw. - Resident Mode (
ResidentServer.cs/ResidentClient.cs) enables low-latency document editing by keeping files in memory between operations. - MCP integration (
McpServer.cs) exposes all functionality to AI agents through JSON-RPC, while the npm SDK (npm/officecli.js) provides JavaScript bindings. - All commands support
--jsonoutput for deterministic automation, and theexamples/folder contains runnable shell and Python scripts for Word tables, sections, formatting, and revisions.
Frequently Asked Questions
Does OfficeCLI require Microsoft Office to be installed?
No. OfficeCLI is a completely self-contained binary that creates and manipulates Office Open XML files directly without any dependency on Microsoft Office or LibreOffice. The tool implements its own rendering engine for converting documents to HTML and PNG formats.
What file formats does OfficeCLI support?
OfficeCLI natively supports Word (.docx), Excel (.xlsx), and PowerPoint (.pptx) files according to the Office Open XML specification. The handlers in src/officecli/Handlers/ provide format-specific implementations while maintaining a consistent command interface across all three document types.
How do I use OfficeCLI for multiple rapid edits without reopening the file?
Use Resident Mode by running officecli open <file> to load the document into memory, execute your set, add, or remove commands with reduced latency, then run officecli close <file> to persist changes. This mode is implemented via named pipes in ResidentServer.cs and is ideal for AI agent loops or interactive editing sessions.
Can OfficeCLI integrate with Claude, Cursor, or other AI coding assistants?
Yes. Run officecli mcp <agent-name> to register OfficeCLI as a tool provider via the Model Context Protocol. Once registered, AI agents can invoke document operations through JSON-RPC without requiring direct shell access. The McpServer.cs file implements the protocol server, exposing all document manipulation commands to supported agents.
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 →