How iofficeai/officecli works
Purpose and entry points
OfficeCLI is a self-contained, cross-platform .NET CLI for creating, reading, modifying, validating, rendering, and batch-processing OOXML Word, Excel, and PowerPoint files without Office. Main process entry is src/officecli/Program.cs; command registration/parsing is centralized in src/officecli/CommandBuilder.cs. Distribution wrappers include install.sh, install.ps1, and the npm launcher npm/officecli.js.
Command and document dispatch
The command layer maps create/view/get/query/mutation, raw XML, batch, merge, watch, install, plugins, resident, and MCP commands to shared operations and format handlers. src/officecli/CommandBuilder.Batch.cs defines batch command wiring; src/officecli/Handlers/DocumentHandlerFactory.cs selects the handler from file type; src/officecli/Core/IDocumentHandler.cs is the principal format boundary.
Format-specific OOXML manipulation
Three large handler families implement the semantic DOM and OOXML mutations:
• Word: src/officecli/Handlers/WordHandler.cs, src/officecli/Handlers/Word/WordHandler.Set.Dispatch.cs, src/officecli/Handlers/Word/WordBatchEmitter.cs
• Excel: src/officecli/Handlers/ExcelHandler.cs, src/officecli/Handlers/Excel/ExcelHandler.Set.cs, src/officecli/Handlers/Excel/ExcelBatchEmitter.cs
• PowerPoint: src/officecli/Handlers/PowerPointHandler.cs, src/officecli/Handlers/Pptx/PowerPointHandler.Mutations.cs, src/officecli/Handlers/Pptx/PptxBatchEmitter.cs
Handlers expose stable path/selector-based elements, while batch emitters serialize document structure into replayable operations. Raw XML commands remain an explicit escape hatch via src/officecli/Core/RawXmlHelper.cs.
Shared document engines
Core services own cross-format capabilities: atomic package persistence (src/officecli/Core/AtomicPackageWriter.cs), template placeholder replacement (src/officecli/Core/TemplateMerger.cs), native chart construction/rendering (src/officecli/Core/Chart/ChartHelper.cs), Mermaid parsing/layout into editable diagrams (src/officecli/Core/Diagram/DiagramCompiler.cs), and Excel formula evaluation (src/officecli/Core/Formula/FormulaEvaluator.cs). These services are invoked by handlers rather than exposed as independent applications.
Rendering, preview, and quality loop
Handlers generate render inputs for a common renderer registry, producing HTML/SVG/screenshots and document issue views. Key boundary paths are src/officecli/Core/Rendering/RendererRegistry.cs, src/officecli/Handlers/Rendering/BasicRenderers.cs, and format-specific preview emitters such as src/officecli/Handlers/Pptx/PowerPointHandler.HtmlPreview.cs. PNG screenshot generation uses a headless-browser path (src/officecli/Core/HtmlScreenshot.cs). watch serves a local auto-refresh preview through src/officecli/Core/Watch/WatchServer.cs.
Stateful and agent-facing integration
Resident mode keeps documents in memory across CLI calls over local IPC, deferring or controlling disk flushes: src/officecli/ResidentServer.cs, src/officecli/ResidentClient.cs, src/officecli/Core/ResidentFlushPolicy.cs. The MCP server exposes document operations over JSON-RPC for agent clients (src/officecli/McpServer.cs, src/officecli/McpInstaller.cs). Thin Node and Python SDKs use this resident protocol: sdk/node/index.js and sdk/python/officecli.py.
Extensibility, contracts, and delivery
Plugin processes provide format handlers, exporters, and dump readers behind an isolated protocol: src/officecli/Core/Plugins/PluginRegistry.cs, src/officecli/Core/Plugins/PluginProcess.cs, plugins/plugin-protocol.md. JSON help schemas define the supported semantic command surface and are loaded at runtime from schemas/help/ through src/officecli/Help/SchemaHelpLoader.cs. Builds require .NET 10 but publish self-contained native binaries via build.sh; release packaging targets npm, PyPI, and SDK channels through .github/workflows/publish-npm.yml, .github/workflows/publish-pypi.yml, and .github/workflows/publish-sdk.yml.
Main entry points: CommandBuilder.cs Command builder · RendererRegistry.cs Renderer registry · IDocumentHandler.cs Document handler contract · WordHandler.cs Word handler
Components 20
CLI & Contracts
- CLI entry
src/officecli/Program.cs - Command builder · Registers document, batch, watch, plugin, resident, and MCP commands.
src/officecli/CommandBuilder.cs - Help schemas · Loads the semantic command surface from JSON schemas.
src/officecli/Help/SchemaHelpLoader.cs
OOXML Handlers
- Handler factory
src/officecli/Handlers/DocumentHandlerFactory.cs - Document handler contract
src/officecli/Core/IDocumentHandler.cs - Word handler · Supports selector-based mutations and batch emission.
src/officecli/Handlers/WordHandler.cs - Excel handler · Supports selector-based mutations and batch emission.
src/officecli/Handlers/ExcelHandler.cs - PowerPoint handler · Supports mutations, batch emission, and preview output.
src/officecli/Handlers/PowerPointHandler.cs
Shared Engines
- Raw XML helper
src/officecli/Core/RawXmlHelper.cs - Atomic package writer
src/officecli/Core/AtomicPackageWriter.cs - Document engines · Template merge, charts, diagrams, and formula evaluation invoked by handlers.
src/officecli/Core/TemplateMerger.cs - Renderer registry
src/officecli/Core/Rendering/RendererRegistry.cs - Basic renderers · Produces render and issue-view outputs.
src/officecli/Handlers/Rendering/BasicRenderers.cs - HTML screenshots · Generates PNG screenshots from HTML previews.
src/officecli/Core/HtmlScreenshot.cs - Watch server · Serves auto-refresh document previews.
src/officecli/Core/Watch/WatchServer.cs
Stateful & External Access
- Resident server · Keeps documents in memory and controls disk flushes.
src/officecli/ResidentServer.cs - MCP server · Exposes document operations to agent clients.
src/officecli/McpServer.cs - Plugin registry · Discovers external format handlers, exporters, and dump readers.
src/officecli/Core/Plugins/PluginRegistry.cs - Node & Python SDKs · Use the resident protocol.
sdk/node/index.js
Distribution
- Release channels · Publishes npm, PyPI, and SDK distributions.
.github/workflows/publish-npm.yml
Connections 26
- CLI entry → Command builder: starts
- Command builder → Help schemas: loads help
- Command builder → Handler factory: dispatches document commands
- Handler factory → Document handler contract: selects implementation
- Document handler contract → Word handler: implemented by
- Document handler contract → Excel handler: implemented by
- Document handler contract → PowerPoint handler: implemented by
- Command builder → Raw XML helper: raw XML commands
- Word handler → Document engines: uses
- Excel handler → Document engines: uses
- PowerPoint handler → Document engines: uses
- Word handler → Atomic package writer: persists packages
- Excel handler → Atomic package writer: persists packages
- PowerPoint handler → Atomic package writer: persists packages
- Word handler → Renderer registry: supplies render input
- Excel handler → Renderer registry: supplies render input
- PowerPoint handler → Renderer registry: supplies render input
- Renderer registry → Basic renderers: selects renderer
- Basic renderers → HTML screenshots: HTML to PNG
- Command builder → Watch server: watch command
- Watch server → Renderer registry: refreshes previews
- Command builder → Resident server: resident command
- Node & Python SDKs → Resident server: local IPC
- Command builder → MCP server: MCP command
- Command builder → Plugin registry: loads extensions
- Release channels → CLI entry: packages CLI