$npx -y skills add iOfficeAI/OfficeCLI --skill officecli-docxUse this skill any time a .docx file is involved -- as input, output, or both. This includes: creating Word documents, reports, letters, memos, or proposals; reading, parsing, or extracting text from any .docx file; editing, modifying, or updating existing documents; working with
| 1 | # OfficeCLI DOCX Skill |
| 2 | |
| 3 | ## Setup |
| 4 | |
| 5 | If `officecli` is missing: |
| 6 | |
| 7 | - **macOS / Linux**: `curl -fsSL https://d.officecli.ai/install.sh | bash` |
| 8 | - **Windows (PowerShell)**: `irm https://d.officecli.ai/install.ps1 | iex` |
| 9 | |
| 10 | Verify with `officecli --version` (open a new terminal if PATH hasn't picked up). If install fails, download a binary from https://github.com/iOfficeAI/OfficeCLI/releases. |
| 11 | |
| 12 | ## ⚠️ Help-First Rule |
| 13 | |
| 14 | **This skill teaches what good docx looks like, not every command flag. When a property name, enum value, or alias is uncertain, consult help BEFORE guessing.** |
| 15 | |
| 16 | ```bash |
| 17 | officecli help docx # List all docx elements |
| 18 | officecli help docx <element> # Full element schema (e.g. paragraph, field, numbering, watermark, toc) |
| 19 | officecli help docx <verb> <element> # Verb-scoped (e.g. add field, set section) |
| 20 | officecli help docx <element> --json # Machine-readable schema |
| 21 | ``` |
| 22 | |
| 23 | Help is pinned to the installed CLI version. When this skill and help disagree, **help is authoritative**. |
| 24 | |
| 25 | ## Mental Model |
| 26 | |
| 27 | A `.docx` is a ZIP of XML parts (`document.xml`, `styles.xml`, `numbering.xml`, `header*.xml`, `footer*.xml`, `comments.xml`, …). Everything the user sees — headings, tables, page numbers, TOC, tracked changes — is XML inside that ZIP. `officecli` gives you a semantic-path API (`/body/p[1]/r[2]`) over it, so you almost never touch raw XML; when you must, use `raw-set` (see the XML appendix). |
| 28 | |
| 29 | ## Shell & Execution Discipline |
| 30 | |
| 31 | docx paths contain `[]`; some prop values contain `$`. Both are shell metacharacters. Escaping happens at three layers — keep them separate. |
| 32 | |
| 33 | 1. **Shell.** ALWAYS quote element paths: `"/body/p[1]"`, not `/body/p[1]` (zsh/bash glob `[N]`). Single-quote any value containing `$`: `--prop text='$50M'` — at any length, the whole value inside one pair of single quotes. Unquoted `$50M` is stripped to `M`; mixing `'…$var…'` and `"…$50…"` on one long string is where the `$50` silently vanishes. |
| 34 | 2. **CLI (`text=`).** The two-char escapes `\n` and `\t` ARE interpreted in `--prop text=` — `\n` becomes a `<w:br/>` soft line break, `\t` a `<w:tab/>` — consistently across docx / pptx / xlsx. Double them (`\\n`) for a literal backslash-n (rarely wanted). This applies to row-level table `c1…cN` shortcuts too (`\n` → `<w:br/>` within the cell). |
| 35 | 3. **JSON (batch).** A real newline can also be passed as `"\n"` in the JSON string of a `batch` heredoc; same result. |
| 36 | |
| 37 | If in doubt, `view text` after writing and compare character-for-character. |
| 38 | |
| 39 | **Incremental execution.** `officecli` mutates the file on every call. Run commands one at a time and check each exit code — a 50-command script that fails at command 3 cascades silently. After any structural op (new style, table, TOC, section break) run `get` on it before stacking more. |
| 40 | |
| 41 | **Open/save lifecycle:** `officecli open <file>` at the start, `officecli save <file>` at the end to flush to disk — `save` only writes and leaves the resident warm for follow-up edits; reach for `officecli close <file>` only to release the resident on a one-shot handoff. Both are always safe (never error or lose work). For many paragraphs of one style, use `batch` (one pass for the whole array). **Flush only at the non-officecli boundary:** officecli's own reads always see your edits; run `save`/`close` only before a non-officecli program reads the file (python-docx, Word, a renderer, delivery). |
| 42 | |
| 43 | **`$FILE` convention.** All commands use `"$FILE"` — set it once (`FILE="your-doc.docx"`). Never copy a literal `doc.docx` / `review.docx` into output — always substitute your actual target. |
| 44 | |
| 45 | ## Requirements for Outputs |
| 46 | |
| 47 | Deliverable standards every document MUST meet — know these before reaching for a command. |
| 48 | |
| 49 | **Clear hierarchy.** Every non-trivial document has Title → Heading 1 → Heading 2 → body, not a wall of unstyled `Normal` paragraphs. If `view outline` shows one flat list, the hierarchy is missing. |
| 50 | |
| 51 | **Explicit heading sizes** (Word default style sizes drift between templates): **H1 ≥ 18pt** (20pt for long reports), H2 = 14pt bold, H3 = 12pt bold, body = 11–12pt, line spacing 1.15–1.5x. Prefer `style=Heading1` over inline sizes so a retheme touches the definition once — but set explicit sizes when you can't trust the template's styles. |
| 52 | |
| 53 | **One body font, one accent.** One readable body font (Calibri, Cambria, Georgia, Times New Roman); accent color for heading emphasis or table headers, not rainbow formatting. |
| 54 | |
| 55 | **Spacing through properties.* |