DOCX
Use this skill whenever the user asks to create, revise, comment on, or inspect a .docx document.
Default Workflow
- For new documents with straightforward structure, write Markdown first and convert it with
pandoc. - For programmatic creation, write a CommonJS
.cjsscript and userequire("docx"). The container exposes global Node packages throughNODE_PATH; avoid bare ESMimport "docx"examples. - For editing an existing
.docx, never round-trip the original file throughdocxorpandoc. Unpack the OOXML, edit the XML you need, and repack it.
Existing-File Editing Workflow
node skills/office/unpack.cjs input.docx tmp/docx-edit
node skills/office/validate.cjs tmp/docx-edit
node skills/office/pack.cjs tmp/docx-edit output.docx
Edit only the relevant parts under tmp/docx-edit/word/:
document.xmlfor the main bodystyles.xmlfor stylesnumbering.xmlfor list definitionsheader*.xml/footer*.xmlfor page furniture_rels/*.relswhen you add new parts
Rules
- Preserve existing formatting by editing OOXML directly for in-place revisions.
- Escape XML-sensitive characters (
&,<,>) and preservexml:space="preserve"when surrounding spaces matter. - Use DXA table widths and explicit cell widths instead of percentages when layout must survive Word and Google Docs.
- Keep relationship ids, comment ids, and content-type overrides consistent when adding parts.
- Never write plain text or placeholder text directly to a
.docxfile path. If generation fails, stop and report the error.
Comments And Reviews
- Use
node skills/docx/scripts/comment.cjs --helpto insert a comment around an exact text match inside an unpacked DOCX tree. - Use
node skills/docx/scripts/accept_changes.cjs /tmp/docx-edit --jsonto accept straightforward tracked changes after unpacking. - The helper currently targets
word/document.xml. For complex tracked changes, nested fields, or multi-run matches, edit the OOXML manually after unpacking.
Useful Commands
pandoc draft.docx -t gfm -o draft.md
pandoc outline.md -o report.docx
Templates
- Prefer user-provided
.docxtemplates from the current workspace for letterhead, memos, and branded report formats. - Preserve headers, footers, styles, numbering, and section geometry unless the user explicitly asks for a layout change.
Minimal Creation Pattern
const fs = require("node:fs");
const { Document, Packer, Paragraph, TextRun } = require("docx");
const document = new Document({
sections: [
{
children: [
new Paragraph({
children: [new TextRun({ text: "Quarterly Update", bold: true })],
}),
new Paragraph("Prepared for leadership review."),
],
},
],
});
Packer.toBuffer(document).then((buffer) => {
fs.writeFileSync("quarterly-update.docx", buffer);
});