OfficeCLI View Modes: Complete Guide to Document Inspection and Export
OfficeCLI supports ten distinct view modes—including outline, text, annotated, stats, issues, html, svg, screenshot, pdf, and forms—that transform Office documents into structured data, visual previews, or export-ready formats.
The iOfficeAI/OfficeCLI repository provides a powerful command-line interface for programmatic Office document manipulation. Its view verb serves as the primary entry point for read-only document representation, offering specialized OfficeCLI view modes for everything from structural analysis to pixel-accurate rendering.
OfficeCLI View Command Architecture
The view command is dispatched in src/officecli/ResidentServer.cs (lines 1080–1082), which routes requests to format-specific handlers. Each handler implements view modes tailored to its document type:
WordHandler.View.cshandles Word documentsPptHandler.View.cshandles PowerPoint presentationsExcelHandler.View.cshandles Excel spreadsheets
The rendering pipeline utilizes HtmlPreview and SvgRenderer classes, with a shared state machine ensuring text and visual markers remain synchronized (see WordHandler.StyleList.cs lines 1245–1248).
Text and Structure Analysis Modes
These modes extract or analyze document content without visual rendering.
Outline Mode
outline generates a hierarchical representation of document structure—slides in PowerPoint or headings in Word—ideal for quickly understanding document organization.
Text Mode
text performs plain-text extraction, emitting raw content without formatting. This mode walks the OOXML DOM to strip all styling, producing content suitable for text-only processing or search indexing.
Annotated Mode
annotated displays text with inline markup markers indicating runs, styles, and formatting boundaries. Use this for debugging formatting issues or analyzing style applications.
Statistics Mode
stats (alias page-count) returns high-level metadata including page counts, slide totals, and element statistics. This validates document size before export operations.
Issues Mode
issues enumerates structural problems such as content overflow, missing alt-text, or accessibility violations, enabling automated quality checks before delivery.
Visual Rendering and Export Modes
These modes generate viewable files or graphics from Office documents.
HTML Preview
html generates self-contained HTML previews with inlined assets, suitable for browser rendering or AI agent consumption. The built-in rendering engine produces these via the HtmlPreview class.
SVG Rendering
svg creates vector renderings of individual pages or slides. This mode invokes the SvgRenderer for scalable graphic output suitable for further manipulation.
Screenshot Capture
screenshot renders pages or slides to PNG images, supporting --page for specific pages and --grid for contact-sheet layouts. This enables pixel-accurate visual audits of layout bugs.
PDF Export
pdf exports documents to PDF format via the exporter plugin, producing archival or distribution-ready output.
Form Inspection
forms (available for .docx via the format-handler plugin) renders interactive form fields as visual representations, validating fillable template structures.
Command Syntax and Practical Examples
The standard syntax follows:
officecli view <file> <mode> [options]
Retrieve a PowerPoint outline:
officecli view deck.pptx outline
Extract plain text from a Word document:
officecli view report.docx text
Generate a browser-ready HTML preview:
officecli view proposal.docx html -o ./proposal.html
Capture a specific slide as PNG:
officecli view deck.pptx screenshot --page 2 -o /tmp/slide2.png
Create an SVG of the first slide:
officecli view deck.pptx svg --page 1 -o /tmp/slide1.svg
Export JSON-formatted issue reports:
officecli view report.docx issues --json
Generate a contact sheet of all slides:
officecli view deck.pptx screenshot --grid auto -o ./deck-contact-sheet.png
Summary
- OfficeCLI provides ten view modes across three handlers (Word, PowerPoint, Excel) for comprehensive document inspection.
- Text-based modes (outline, text, annotated, stats, issues) analyze structure and content via OOXML DOM traversal.
- Visual modes (html, svg, screenshot) leverage the
HtmlPreviewandSvgRendererclasses for graphical output. - Export modes (pdf, forms) require plugin extensions for additional format support.
- The command dispatcher in
ResidentServer.csroutes all view requests to specialized handlers likeWordHandler.View.csandPptHandler.View.cs.
Frequently Asked Questions
What is the difference between text and annotated view modes in OfficeCLI?
The text mode extracts raw plain text by walking the OOXML DOM and stripping all formatting, producing clean content for search or processing. The annotated mode preserves inline markup markers that indicate style runs and formatting boundaries, making it suitable for debugging document structure according to the source implementation in WordHandler.View.cs.
How do I export a specific slide as PNG using OfficeCLI?
Use the screenshot mode with the --page option. For example: officecli view deck.pptx screenshot --page 2 -o slide2.png. You can also use --grid auto to generate a contact sheet of all slides in a single PNG file, leveraging the rendering pipeline shared with the HtmlPreview class.
Which OfficeCLI view modes require plugins?
The pdf mode requires the exporter plugin, and the forms mode requires the format-handler plugin (available only for .docx files). All other modes—including outline, text, html, svg, and screenshot—are built into the core OfficeCLI distribution as implemented in the primary handler files.
Where is the view command logic implemented in the OfficeCLI source code?
The view verb is dispatched in src/officecli/ResidentServer.cs (lines 1080–1082). Format-specific implementations reside in WordHandler.View.cs, PptHandler.View.cs, and ExcelHandler.View.cs. Visual rendering logic is contained in the HtmlPreview and SvgRenderer classes, with style consistency managed in WordHandler.StyleList.cs (lines 1245–1248).
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 →