# OfficeCLI Examples Comprehensive examples demonstrating OfficeCLI capabilities for Word, Excel, and PowerPoint automation. ## πŸ“‚ Directory Structure Every example below ships all four files β€” `.{md,sh,py,}` β€” even where the tree abbreviates. Only `ppt/templates/styles/*/build*.sh` are `.sh`-only. ``` examples/ β”œβ”€β”€ README.md # This file β”œβ”€β”€ word/ # πŸ“„ Word examples β€” *.{md,sh,py,docx} β”‚ β”œβ”€β”€ formulas.{md,sh,py,docx} # LaTeX math/chemistry/physics formulas β”‚ β”œβ”€β”€ tables.{md,sh,py,docx} # styled tables β”‚ β”œβ”€β”€ textbox.{md,sh,py,docx} # formatted text boxes β”‚ β”œβ”€β”€ charts.{md,sh,py,docx} # inline charts (14 types incl. treemap/waterfall) β”‚ β”œβ”€β”€ run-formatting.{md,sh,py,docx} # run/character property surface β”‚ β”œβ”€β”€ paragraph-formatting.{md,sh,py,docx} # paragraph property surface β”‚ β”œβ”€β”€ document-formatting.{md,sh,py,docx} # document-level property surface β”‚ β”œβ”€β”€ sections.{md,sh,py,docx} # section layout β€” multi-column, footnote/endnote props, per-section page setup β”‚ β”œβ”€β”€ content-controls.{md,sh,py,docx} # SDT content controls β€” text/dropdown/combobox/date/picture/group intake form β”‚ β”œβ”€β”€ fields.{md,sh,py,docx} # field codes (PAGE/DATE/REF/IF/HYPERLINK) + auto-populating table of contents β”‚ β”œβ”€β”€ pictures.{md,sh,py,docx} # inline/floating images β€” crop, alt, wrap, behind-text, absolute position β”‚ β”œβ”€β”€ numbering.{md,sh,py,docx} # list/numbering styles β”‚ β”œβ”€β”€ diagram.{md,sh,py,docx} # Mermaid diagrams β€” native editable shapes + full-fidelity PNG β”‚ └── revisions.{md,sh,py,docx} # tracked-change (revision) API β”œβ”€β”€ excel/ # πŸ“Š Excel examples β€” *.{md,sh,py,xlsx} β”‚ β”œβ”€β”€ cell-formatting.{md,sh,py,xlsx} # full cell property surface (fonts/fills/borders/numFmt/data) β”‚ β”œβ”€β”€ conditional-formatting.{md,sh,py,xlsx} β”‚ β”œβ”€β”€ data-validation.{md,sh,py,xlsx} # dropdown lists, number/date/text/custom rules, input & error messages β”‚ β”œβ”€β”€ sheet-settings.{md,sh,py,xlsx} # freeze panes, print area/titles, headers/footers, display & protection β”‚ β”œβ”€β”€ sparklines.{md,sh,py,xlsx} # in-cell line/column/win-loss mini charts + point markers β”‚ β”œβ”€β”€ workbook-settings.{md,sh,py,xlsx} β”‚ β”œβ”€β”€ pivot-tables.{md,sh,py,xlsx} β”‚ β”œβ”€β”€ slicers.{md,sh,py,xlsx} # pivot-table slicers (field/caption/columnCount/rowHeight) β”‚ β”œβ”€β”€ shapes.{md,sh,py,xlsx} # drawing shapes β€” geometry, flip, glow, gradient, reflection, outline β”‚ β”œβ”€β”€ charts.{md,sh,py,xlsx} # master chart showcase β”‚ └── charts/ # per-type chart scripts β€” charts-.{md,sh,py,xlsx} β”‚ (demo, basic, advanced, extended, area, bar, boxwhisker, β”‚ bubble, column, combo, histogram, line, pie, radar, β”‚ scatter, stock, waterfall) └── ppt/ # 🎨 PowerPoint examples β€” *.{md,sh,py,pptx} β”œβ”€β”€ presentation.{md,sh,py,pptx} β”œβ”€β”€ presentation-settings.{md,sh,py,pptx} β”œβ”€β”€ diagram.{md,sh,py,pptx} # Mermaid diagrams β€” native editable shapes + full-fidelity PNG β”œβ”€β”€ animations.{md,sh,py,pptx} β”œβ”€β”€ video.{md,sh,py,pptx} β”œβ”€β”€ 3d-model.{md,sh,py,pptx} β”œβ”€β”€ charts/ # charts-.{md,sh,py,pptx} β”‚ (column, bar, line, pie, doughnut, area, scatter, β”‚ bubble, radar, stock, combo, waterfall, 3d, advanced) β”œβ”€β”€ tables/ # tables-.{md,sh,py,pptx} β”‚ (basic, styled, merged, borders, rows-cols, financial, nested) β”œβ”€β”€ transitions/ # transitions-.{md,sh,py,pptx} β”‚ (basic, directional, shapes, bands, dynamic, modern, random, timing, morph) β”œβ”€β”€ shapes/ # shapes-.{md,sh,py,pptx} β”‚ (basic, connectors, effects, typography) β”œβ”€β”€ textboxes/ # textboxes-.{md,sh,py,pptx} β”‚ (basic, advanced) β”œβ”€β”€ pictures/ # pictures-basic.{md,sh,py,pptx} β”œβ”€β”€ ole/ # ole-embed.{md,sh,py,pptx} β€” embedded Excel/Word OLE objects └── templates/styles/*/build*.sh # full-deck template generators (.sh only) ``` Each example ships the same **four-file set**: | File | Role | |------|------| | `.md` | Walkthrough β€” what the example demonstrates and the key techniques | | `.sh` | **CLI** build script β€” drives the `officecli` binary directly (`officecli create / add / set / close / validate`) | | `.py` | **SDK** build script β€” drives the [`officecli` Python SDK](../sdk/python/) (`import officecli`; `with officecli.create(...) as doc: doc.batch([...])`) | | `.` | Pre-generated output (`.docx` / `.xlsx` / `.pptx`) | The `.sh` and `.py` are **equivalent twins** β€” both regenerate the same output document, one via the command line and one via the Python SDK. Run whichever fits your workflow. > The full-deck template generators under `ppt/templates/styles/*/build*.sh` are > standalone deck builders, not four-file API examples, so they ship as `.sh` only. --- ## πŸš€ Quick Start Every example runs **two equivalent ways** β€” pick one: ```bash bash .sh # via the officecli CLI binary python3 .py # via the officecli Python SDK (pip install officecli-sdk) ``` Both regenerate the same output document. The commands below show one form per example; swap `bash …​.sh` ⇄ `python3 …​.py` freely. ### By Document Type **Word (.docx):** ```bash cd word bash run-formatting.sh # Run/character formatting: bold/underline/strike/caps/super-sub/fonts/effects bash paragraph-formatting.sh # Paragraph formatting: align/indent/spacing/pagination/shading/markRPr bash formulas.sh # LaTeX math formulas bash tables.sh # Styled tables bash textbox.sh # Formatted text boxes bash numbering.sh # List/numbering styles bash revisions.sh # Tracked-change (revision) API β€” ins/del/format/move/cellChange ``` **Excel (.xlsx):** ```bash cd excel python cell-formatting.py # Full cell property surface: fonts, fills, borders, number formats, formulas/links bash charts.sh # Master chart showcase (8 chart types in one workbook) bash charts/charts-basic.sh # Per-type high-level examples (any charts/charts-.sh) python charts/charts-line.py # Single-type example (any charts/charts-.py) python pivot-tables.py # Pivot tables ``` **PowerPoint (.pptx):** ```bash cd ppt bash presentation.sh # Morph transitions / full deck bash animations.sh # Animation effects python video.py # Video embedding bash 3d-model.sh # 3D model embedding bash diagram.sh # Mermaid diagrams β€” render=native (editable shapes) + render=image (PNG) python charts/charts-column.py # PowerPoint chart examples (any charts/charts-.py) bash tables/tables-basic.sh # Tables β€” minimal create + populate bash tables/tables-styled.sh # 9 built-in styles + banding flags + rowHeight/name= bash tables/tables-merged.sh # gridSpan horizontal merge bash tables/tables-borders.sh # Per-side / per-cell borders bash tables/tables-rows-cols.sh # add row/column, per-row height, gridSpan + merge.down bash tables/tables-financial.sh # End-to-end financial deck bash transitions/transitions-basic.sh # cut/fade/dissolve/flash + 'none' clear bash transitions/transitions-directional.sh # push/wipe/cover/uncover Γ— direction matrix bash transitions/transitions-shapes.sh # circle/diamond/wedge/wheel/zoom bash transitions/transitions-bands.sh # blinds/strips/split/checker bash transitions/transitions-dynamic.sh # 2010+ Exciting gallery (vortex/flip/...) bash transitions/transitions-modern.sh # 2013+ Exciting gallery (pageCurl/airplane/origami/...) bash transitions/transitions-random.sh # newsflash / random bash transitions/transitions-timing.sh # speed, duration, advanceTime, advanceClick bash transitions/transitions-morph.sh # 2016+ Morph tweening bash shapes/shapes-basic.sh # geometries, fills, outlines, rotation, basic effects bash shapes/shapes-connectors.sh # straight/elbow/curve connectors + groups bash shapes/shapes-effects.sh # autoFit, flip, image fill, 3D, softEdge, links, zorder bash shapes/shapes-typography.sh # spacing, kern, case, RTL direction, font.cs, lang bash textboxes/textboxes-basic.sh # alignment, bullets, runs, per-script fonts bash textboxes/textboxes-advanced.sh # per-paragraph overrides, indents, per-run typography python pictures/pictures-basic.py # picture src/crop/rotation/links (needs Pillow) ``` --- ## πŸ“š Documentation by Type ### πŸ“„ [Word Examples β†’](word/) - Run / character formatting β€” weight, underline variants, strike/dstrike, caps/smallCaps, super/subscript, color/size/highlight, per-script fonts, text effects, character spacing, language - Paragraph formatting β€” alignment, indentation, spacing, pagination flags, paragraph-level run formatting, shading, paragraph-mark (markRPr) formatting, outline level - Mathematical formulas (LaTeX) - Complex tables - Text boxes and styling - Numbering / list showcases - Mermaid diagrams β€” `render=native` (editable flowchart / sequence shapes) and `render=image` (inline full-fidelity PNG of every mermaid type) ### πŸ“Š [Excel Examples β†’](excel/) - Cell formatting β€” the full `cell` property surface across 5 sheets: fonts (name/size/bold/italic/color/underline/strike), fills (hex/named/rgb) + alignment (h/v/wrap/RTL), borders (shorthand/all/per-side/color), number formats (thousands/%/currency/date/scientific/accounting), and data (value/type/formula/link/locked/merge) - Master and per-type chart scripts (line, bar, pie, scatter, stock, waterfall, …) - Pivot tables - Number formatting and styling ### 🎨 [PowerPoint Examples β†’](ppt/) - Slide / shape construction - Morph transitions and animations - Video and 3D model embedding - Mermaid diagrams β€” `render=native` (editable flowchart / sequence shapes + connectors) and `render=image` (full-fidelity PNG via mermaid.js, covering every mermaid type); `mermaid` / `text` / `dsl` / `src` source, placement box, `get` / `set` / `remove` the whole diagram as one group - Native chart examples (column, bar, line, pie, doughnut, area, scatter, bubble, radar, stock, combo, waterfall, 3D, advanced) - Tables β€” basic, built-in styles, merged cells, borders, row/column ops, real-world financial deck - Slide transitions β€” all 59 schema tokens covered across 9 trios: basic, directional, shape, band, dynamic 3D (p14), modern (p15 β€” Page Curl, Airplane, Origami, …), random, timing, and Morph - Shapes β€” full pptx/shape property surface across 4 trios: geometries + fills + outlines + rotation + basic effects (basic), straight/elbow/curve connectors + groups (connectors), autoFit + flip + image-fill + 3D scene + softEdge + click links + zorder (effects), paragraph/char spacing + kerning + smallCaps + RTL + complex-script font + BCP-47 lang (typography) - Textboxes β€” alignment, bulleted/numbered lists, run-by-run rich text (bold/italic/color/super/sub/strike), per-script fonts (Latin/EastAsian), vertical alignment and padding - Pictures β€” file path / URL / data-URI / `name=` for `src=`, all crop forms (symmetric, V,H, per-edge L/T/R/B), rotation, clickable links (URL / slide jump / named action) --- ## πŸ”§ Common Patterns ### Create and Populate ```bash #!/bin/bash set -e FILE="document.docx" officecli create "$FILE" officecli add "$FILE" /body --type paragraph --prop text="Hello World" officecli validate "$FILE" ``` ### Batch Operations ```bash cat << 'EOF' > commands.json [ {"command":"add","parent":"/body","type":"paragraph","props":{"text":"Para 1"}}, {"command":"set","path":"/body/p[1]","props":{"bold":"true","size":"24"}} ] EOF officecli batch document.docx < commands.json ``` ### Resident Mode (3+ operations) ```bash officecli open document.docx officecli add document.docx /body --type paragraph --prop text="Fast operation" officecli set document.docx /body/p[1] --prop bold=true officecli close document.docx ``` ### Query and Modify ```bash # Find all Heading1 paragraphs officecli query report.docx "paragraph[style=Heading1]" --json # Change their color officecli set report.docx /body/p[1] --prop color=FF0000 ``` --- ## πŸ“Š Quick Reference ### Document Types | Format | Extension | Create | View | Modify | |--------|-----------|--------|------|--------| | Word | .docx | βœ“ | βœ“ | βœ“ | | Excel | .xlsx | βœ“ | βœ“ | βœ“ | | PowerPoint | .pptx | βœ“ | βœ“ | βœ“ | ### Common Commands | Command | Purpose | Example | |---------|---------|---------| | `create` | Create blank document | `officecli create file.docx` | | `view` | View content | `officecli view file.docx text` | | `get` | Get element | `officecli get file.docx /body/p[1]` | | `set` | Modify element | `officecli set file.docx /body/p[1] --prop bold=true` | | `add` | Add element | `officecli add file.docx /body --type paragraph` | | `remove` | Remove element | `officecli remove file.docx /body/p[5]` | | `query` | CSS-like query | `officecli query file.docx "paragraph[style=Normal]"` | | `batch` | Multiple operations | `officecli batch file.docx < commands.json` | | `validate` | Check schema | `officecli validate file.docx` | ### View Modes | Mode | Description | Usage | |------|-------------|-------| | `text` | Plain text | `officecli view file.docx text` | | `annotated` | Text with formatting | `officecli view file.docx annotated` | | `outline` | Structure | `officecli view file.docx outline` | | `stats` | Statistics | `officecli view file.docx stats` | | `issues` | Problems | `officecli view file.docx issues` | | `html` | HTML preview | `officecli view file.docx html` | | `svg` | SVG preview | `officecli view file.docx svg` | | `forms` | Form fields | `officecli view file.docx forms` | --- ## πŸ’‘ Tips 1. **Explore before modifying:** ```bash officecli view document.docx outline officecli get document.docx /body --depth 2 ``` 2. **Use `--json` for automation:** ```bash officecli query data.xlsx "cell[formula~=SUM]" --json | jq ``` 3. **Check help for properties** (schema reference is under the `help` verb): ```bash officecli help docx set paragraph officecli help xlsx set cell officecli help pptx set shape ``` 4. **Validate after changes:** ```bash officecli validate document.docx ``` 5. **Use resident mode for performance** (3+ operations on same file): ```bash officecli open file.pptx # ... multiple commands ... officecli close file.pptx ``` --- ## 🀝 Contributing Examples 1. **Create script** with clear comments 2. **Test and verify** output 3. **Add to appropriate directory** (word/excel/ppt) 4. **Update directory README** 5. **Submit PR** **Example format:** ```bash #!/bin/bash # Brief description of what this demonstrates # Key techniques: list them here set -e FILE="output.docx" officecli create "$FILE" # ... your commands ... officecli validate "$FILE" echo "Created: $FILE" ``` --- ## πŸ“– More Resources - **[SKILL.md](../SKILL.md)** - Complete command reference for AI agents - **[README.md](../README.md)** - Project overview and installation --- ## πŸ†˜ Getting Help **Top-level help:** ```bash officecli --help # CLI usage officecli help # Schema reference entry point officecli help docx # All docx elements officecli help docx set # Elements that support `set` for docx officecli help docx set paragraph # Settable properties on paragraph officecli help docx paragraph --json # Raw schema JSON officecli help all # Flat dump of every (format, element, property) ``` Format aliases: `wordβ†’docx`, `excelβ†’xlsx`, `ppt`/`powerpointβ†’pptx`. Verbs: `add`, `set`, `get`, `query`, `remove`. --- **Happy automating! πŸš€** For questions or issues, visit [GitHub Issues](https://github.com/iOfficeAI/OfficeCLI/issues).