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.
A .docx file is a ZIP archive containing XML files.
Use local execution for .docx operations in this project.
.docx processing here.docx as plain textpandoc, soffice.py, unpack.py, pack.py, or related scripts through local execAll relative paths in this skill are relative to the docx skill directory, not the project root.
In a project workspace, resolve paths like this:
scripts/office/unpack.py means skills/docx/scripts/office/unpack.pyscripts/office/pack.py means skills/docx/scripts/office/pack.pyscripts/office/validate.py means skills/docx/scripts/office/validate.pyscripts/office/soffice.py means skills/docx/scripts/office/soffice.pyscripts/accept_changes.py means skills/docx/scripts/accept_changes.pyNever resolve these paths as project_root/scripts/....
If you are running commands from the project workspace root, use explicit paths under skills/docx/scripts/....
Never call read_file on a raw .docx file. A .docx file is a ZIP container, not UTF-8 text.
If an uploaded .docx is outside the current working directory, do not keep retrying blocked direct-access commands. Use a workspace-local copy workflow first, then operate on the copied file.
Continue the rewrite pipeline only from extracted text artifacts such as unpacked XML text or pandoc output, not from the original .docx binary.
| Task | Approach |
|---|---|
| Read/analyze content | pandoc or unpack for raw XML |
| Create new document | Use docx-js - see Creating New Documents below |
| Edit existing document | Unpack → edit XML → repack - see Editing Existing Documents below |
Legacy .doc files must be converted before editing:
python skills/docx/scripts/office/soffice.py --headless --convert-to docx document.doc
# Text extraction with tracked changes
pandoc --track-changes=all document.docx -o output.md
# Raw XML access
python skills/docx/scripts/office/unpack.py document.docx unpacked/
python skills/docx/scripts/office/soffice.py --headless --convert-to pdf document.docx
pdftoppm -jpeg -r 150 document.pdf page
To produce a clean document with all tracked changes accepted (requires LibreOffice):
python skills/docx/scripts/accept_changes.py input.docx output.docx
Generate .docx files with JavaScript, then validate. Install: npm install -g docx
const { Document, Packer, Paragraph, TextRun, Table, TableRow, TableCell, ImageRun,
Header, Footer, AlignmentType, PageOrientation, LevelFormat, ExternalHyperlink,
InternalHyperlink, Bookmark, FootnoteReferenceRun, PositionalTab,
PositionalTabAlignment, PositionalTabRelativeTo, PositionalTabLeader,
TabStopType, TabStopPosition, Column, SectionType,
TableOfContents, HeadingLevel, BorderStyle, WidthType, ShadingType,
VerticalAlign, PageNumber, PageBreak } = require('docx');
const doc = new Document({ sections: [{ children: [/* content */] }] });
Packer.toBuffer(doc).then(buffer => fs.writeFileSync("doc.docx", buffer));
After creating the file, validate it. If validation fails, unpack, fix the XML, and repack.
python skills/docx/scripts/office/validate.py doc.docx
// CRITICAL: docx-js defaults to A4, not US Letter
// Always set page size explicitly for consistent results