
Word
Generate correct, render-safe Word .docx files from JavaScript or TypeScript using the docx library without corruption from common formatting mistakes.
Overview
Word is an agent skill most often used in Build (also Ship and Grow) that generates .docx files with the docx npm library using Paragraph-based structure and documented formatting rules to avoid corrupt output.
Install
npx skills add https://github.com/igorwarzocha/opencode-workflows --skill wordWhat is this skill?
- End-to-end docx JS/TS tutorial: Document, Packer, Paragraph, TextRun, tables, images, headers, footers
- Critical rule: never use \n inside TextRun—use separate Paragraph elements for line breaks
- Covers TOC, hyperlinks, footnotes, page breaks, numbering levels, and table cell shading
- Node (Packer.toBuffer) and browser (Packer.toBlob) save patterns
- Warns to read the full skill before generating files to avoid corrupted or broken rendering
Adoption & trust: 593 installs on skills.sh; 124 GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
Your agent keeps emitting .docx code that breaks Word rendering because it treats newlines and complex table or TOC APIs incorrectly.
Who is it for?
Automating proposals, specs, reports, or export features where the deliverable must be a real .docx from Node or browser JavaScript.
Skip if: Markdown-only docs, PDF generation, Google Docs APIs, or Python-docx workflows without adapting to this JS docx tutorial.
When should I use this skill?
User or task requires creating, exporting, or fixing programmatic .docx generation with the JavaScript/TypeScript docx library.
What do I get? / Deliverables
You get spec-compliant docx generation snippets and file output (buffer or blob) that follow library rules for paragraphs, tables, and document sections.
- .docx file on disk via Packer.toBuffer
- Downloadable .docx blob in browser flows
- Reusable Paragraph/Table/Section code patterns
Recommended Skills
Journey fit
Spans multiple journey phases - primary shelf plus alternate fits below.
Build/docs is the primary shelf because the skill is procedural reference for producing document artifacts during implementation and documentation work. Docs subphase covers specs, exports, and deliverable write-ups that ship as formal Word files from code.
Where it fits
Generate an API handoff or architecture spec as a formatted .docx for a stakeholder.
Produce release notes or launch checklist documents with headings and page breaks.
Template customer reports or onboarding packets exported from app data to Word.
How it compares
Procedural docx library reference for JS/TS—not a WYSIWYG template designer or Pandoc markdown conversion shortcut.
Common Questions / FAQ
Who is word for?
Solo builders and small teams whose agents write Node or browser scripts that must output Word documents for clients, compliance, or product exports.
When should I use word?
In build/docs when coding document exports; in ship/launch when packaging release or launch write-ups as .docx; in grow/content when generating repeatable Word templates from data.
Is word safe to install?
Review the Security Audits panel on this Prism page; the skill itself is documentation-style—risk is mainly filesystem writes from generated scripts you run locally.
SKILL.md
READMESKILL.md - Word
# DOCX Library Tutorial Generate .docx files with JavaScript/TypeScript. **Important: Read this entire document before starting.** Critical formatting rules and common pitfalls are covered throughout - skipping sections may result in corrupted files or rendering issues. ## Setup Assumes docx is already installed globally If not installed: `npm install -g docx` ```javascript const { Document, Packer, Paragraph, TextRun, Table, TableRow, TableCell, ImageRun, Media, Header, Footer, AlignmentType, PageOrientation, LevelFormat, ExternalHyperlink, InternalHyperlink, TableOfContents, HeadingLevel, BorderStyle, WidthType, TabStopType, TabStopPosition, UnderlineType, ShadingType, VerticalAlign, SymbolRun, PageNumber, FootnoteReferenceRun, Footnote, PageBreak } = require('docx'); // Create & Save const doc = new Document({ sections: [{ children: [/* content */] }] }); Packer.toBuffer(doc).then(buffer => fs.writeFileSync("doc.docx", buffer)); // Node.js Packer.toBlob(doc).then(blob => { /* download logic */ }); // Browser ``` ## Text & Formatting ```javascript // IMPORTANT: Never use \n for line breaks - always use separate Paragraph elements // ❌ WRONG: new TextRun("Line 1\nLine 2") // ✅ CORRECT: new Paragraph({ children: [new TextRun("Line 1")] }), new Paragraph({ children: [new TextRun("Line 2")] }) // Basic text with all formatting options new Paragraph({ alignment: AlignmentType.CENTER, spacing: { before: 200, after: 200 }, indent: { left: 720, right: 720 }, children: [ new TextRun({ text: "Bold", bold: true }), new TextRun({ text: "Italic", italics: true }), new TextRun({ text: "Underlined", underline: { type: UnderlineType.DOUBLE, color: "FF0000" } }), new TextRun({ text: "Colored", color: "FF0000", size: 28, font: "Arial" }), // Arial default new TextRun({ text: "Highlighted", highlight: "yellow" }), new TextRun({ text: "Strikethrough", strike: true }), new TextRun({ text: "x2", superScript: true }), new TextRun({ text: "H2O", subScript: true }), new TextRun({ text: "SMALL CAPS", smallCaps: true }), new SymbolRun({ char: "2022", font: "Symbol" }), // Bullet • new SymbolRun({ char: "00A9", font: "Arial" }) // Copyright © - Arial for symbols ] }) ``` ## Styles & Professional Formatting ```javascript const doc = new Document({ styles: { default: { document: { run: { font: "Arial", size: 24 } } }, // 12pt default paragraphStyles: [ // Document title style - override built-in Title style { id: "Title", name: "Title", basedOn: "Normal", run: { size: 56, bold: true, color: "000000", font: "Arial" }, paragraph: { spacing: { before: 240, after: 120 }, alignment: AlignmentType.CENTER } }, // IMPORTANT: Override built-in heading styles by using their exact IDs { id: "Heading1", name: "Heading 1", basedOn: "Normal", next: "Normal", quickFormat: true, run: { size: 32, bold: true, color: "000000", font: "Arial" }, // 16pt paragraph: { spacing: { before: 240, after: 240 }, outlineLevel: 0 } }, // Required for TOC { id: "Heading2", name: "Heading 2", basedOn: "Normal", next: "Normal", quickFormat: true, run: { size: 28, bold: true, color: "000000", font: "Arial" }, // 14pt paragraph: { spacing: { before: 180, after: 180 }, outlineLevel: 1 } }, // Custom styles use your own IDs { id: "myStyle", name: "My Style", basedOn: "Normal", run: { size: 28, bold: true, color: "000000" }, paragraph: { spacing: { after: 120 }, alignment: AlignmentType.CENTER } } ], characterStyles: [{ id: "myCharStyle", name: "My Char Style", run: { color: "FF0000", bold: true, underline: { type: UnderlineType.SINGLE } } }] }, sections: [{ properties: { page: { margin: { top: 1440, right: 1440, bottom: 1440, left: 1440 } } }, children: [ new Paragraph({ heading: HeadingLevel.TITLE, children: [new TextRun("Document Title")] }), // U