# OfficeCLI Usage Examples: Creating, Modifying, and Viewing Office Documents Without Installation

> Explore OfficeCLI usage examples for creating, modifying, and viewing Word, Excel, and PowerPoint files without installing Office. Automate document tasks efficiently.

- Repository: [OfficeAI/OfficeCLI](https://github.com/iofficeai/OfficeCLI)
- Tags: usage-examples
- Published: 2026-07-15

---

**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.

```bash

# 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.

```bash

# 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.

```bash
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`](https://github.com/iOfficeAI/OfficeCLI/blob/main/WordHandler.cs) file (located at [`src/officecli/Handlers/Word/WordHandler.cs`](https://github.com/iOfficeAI/OfficeCLI/blob/main/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.

```bash

# 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`](https://github.com/iOfficeAI/OfficeCLI/blob/main/tables.sh)**: Demonstrates Excel-style table creation within Word documents
- **[`sections.sh`](https://github.com/iOfficeAI/OfficeCLI/blob/main/sections.sh)**: Shows section layout manipulation and page formatting
- **[`run-formatting.sh`](https://github.com/iOfficeAI/OfficeCLI/blob/main/run-formatting.sh)**: Illustrates run-level formatting (bold, color, font changes) using the L2 DOM layer
- **[`revisions.sh`](https://github.com/iOfficeAI/OfficeCLI/blob/main/revisions.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.

```bash

# 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.

```bash
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.

```bash

# 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`](https://github.com/iOfficeAI/OfficeCLI/blob/main/src/officecli/ResidentServer.cs) (server-side pipe handling) and [`src/officecli/ResidentClient.cs`](https://github.com/iOfficeAI/OfficeCLI/blob/main/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.

```bash
officecli mcp claude   # registers with Claude Code

officecli mcp cursor   # registers with Cursor

officecli mcp list     # shows registered agents

```

The [`McpServer.cs`](https://github.com/iOfficeAI/OfficeCLI/blob/main/McpServer.cs) file ([`src/officecli/McpServer.cs`](https://github.com/iOfficeAI/OfficeCLI/blob/main/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`](https://github.com/iOfficeAI/OfficeCLI/blob/main/npm/officecli.js) handles binary management transparently.

```javascript
// 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`, and `raw`.
- **Resident Mode** ([`ResidentServer.cs`](https://github.com/iOfficeAI/OfficeCLI/blob/main/ResidentServer.cs)/[`ResidentClient.cs`](https://github.com/iOfficeAI/OfficeCLI/blob/main/ResidentClient.cs)) enables low-latency document editing by keeping files in memory between operations.
- **MCP integration** ([`McpServer.cs`](https://github.com/iOfficeAI/OfficeCLI/blob/main/McpServer.cs)) exposes all functionality to AI agents through JSON-RPC, while the **npm SDK** ([`npm/officecli.js`](https://github.com/iOfficeAI/OfficeCLI/blob/main/npm/officecli.js)) provides JavaScript bindings.
- All commands support `--json` output for deterministic automation, and the `examples/` 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`](https://github.com/iOfficeAI/OfficeCLI/blob/main/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`](https://github.com/iOfficeAI/OfficeCLI/blob/main/McpServer.cs) file implements the protocol server, exposing all document manipulation commands to supported agents.