DOCX creation, editing, and analysis
Overview
A .docx file is a ZIP archive containing XML files.
Quick Reference
| Task |
Approach |
| Read/analyze content |
pandoc or unpack for raw XML |
| Create new document |
Use docx-js — see references/creating.md |
| Edit existing document |
Unpack → edit XML → repack — see references/editing.md |
| Raw XML (tracked changes, comments, images) |
See references/xml.md |
Converting .doc to .docx
Legacy .doc files must be converted before editing:
python scripts/office/soffice.py --headless --convert-to docx document.doc
Reading Content
# Text extraction with tracked changes
pandoc --track-changes=all document.docx -o output.md
# Raw XML access
python scripts/office/unpack.py document.docx unpacked/
Converting to Images
python scripts/office/soffice.py --headless --convert-to pdf document.docx
pdftoppm -jpeg -r 150 document.pdf page
Accepting Tracked Changes
To produce a clean document with all tracked changes accepted (requires LibreOffice):
python scripts/accept_changes.py input.docx output.docx
Detailed references
Implementation details live in references/ (one level deep, loaded only when relevant):
- references/creating.md (~340 lines) — Creating new .docx files with docx-js: setup, validation, page size, styles, lists, tables, images, page breaks, hyperlinks, footnotes, tab stops, multi-column layouts, table of contents, headers/footers, critical rules for docx-js.
- references/editing.md (~60 lines) — Editing existing documents: the unpack → edit XML → repack workflow, common pitfalls.
- references/xml.md (~130 lines) — Raw XML reference: schema compliance, tracked changes, comments, images.
When working on a creating or editing task, read the relevant reference file before generating code.
Dependencies
- pandoc: Text extraction
- docx:
npm install -g docx (new documents)
- LibreOffice: PDF conversion (auto-configured for sandboxed environments via
scripts/office/soffice.py)
- Poppler:
pdftoppm for images
1---2name: docx3description: Use this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files). Triggers include: any mention of 'Word doc', 'word document', '.docx', or requests to produce professional documents with formatting like tables of contents, headings, page numbers, or letterheads. Also use when extracting or reorganizing content from .docx files, inserting or replacing images in documents, performing find-and-replace in Word files, working with tracked changes or comments, or converting content into a polished Word document. If the user asks for a 'report', 'memo', 'letter', 'template', or similar deliverable as a Word or .docx file, use this skill. Do NOT use for PDFs, spreadsheets, Google Docs, or general coding tasks unrelated to document generation.4license: Proprietary. LICENSE.txt has complete terms5---67# DOCX creation, editing, and analysis89## Overview1011A .docx file is a ZIP archive containing XML files.1213## Quick Reference1415| Task | Approach |16|------|----------|17| Read/analyze content | `pandoc` or unpack for raw XML |18| Create new document | Use `docx-js` — see [references/creating.md](references/creating.md) |19| Edit existing document | Unpack → edit XML → repack — see [references/editing.md](references/editing.md) |20| Raw XML (tracked changes, comments, images) | See [references/xml.md](references/xml.md) |2122### Converting .doc to .docx2324Legacy `.doc` files must be converted before editing:2526```bash27python scripts/office/soffice.py --headless --convert-to docx document.doc28```2930### Reading Content3132```bash33# Text extraction with tracked changes34pandoc --track-changes=all document.docx -o output.md3536# Raw XML access37python scripts/office/unpack.py document.docx unpacked/38```3940### Converting to Images4142```bash43python scripts/office/soffice.py --headless --convert-to pdf document.docx44pdftoppm -jpeg -r 150 document.pdf page45```4647### Accepting Tracked Changes4849To produce a clean document with all tracked changes accepted (requires LibreOffice):5051```bash52python scripts/accept_changes.py input.docx output.docx53```5455---5657## Detailed references5859Implementation details live in `references/` (one level deep, loaded only when relevant):6061- **[references/creating.md](references/creating.md)** (~340 lines) — Creating new .docx files with docx-js: setup, validation, page size, styles, lists, tables, images, page breaks, hyperlinks, footnotes, tab stops, multi-column layouts, table of contents, headers/footers, critical rules for docx-js.62- **[references/editing.md](references/editing.md)** (~60 lines) — Editing existing documents: the unpack → edit XML → repack workflow, common pitfalls.63- **[references/xml.md](references/xml.md)** (~130 lines) — Raw XML reference: schema compliance, tracked changes, comments, images.6465When working on a creating or editing task, read the relevant reference file before generating code.6667---6869## Dependencies7071- **pandoc**: Text extraction72- **docx**: `npm install -g docx` (new documents)73- **LibreOffice**: PDF conversion (auto-configured for sandboxed environments via `scripts/office/soffice.py`)74- **Poppler**: `pdftoppm` for images