Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
ailabs-393 avatar

Docx

  • 875 installs
  • 432 repo stars
  • Updated November 11, 2025
  • ailabs-393/ai-labs-claude-skills

DOCX is a Claude skill that teaches developers to programmatically generate polished, formatted Word documents using the JavaScript docx library without manual layout work in Microsoft Word.

About

DOCX is a Claude skill from ai-labs-claude-skills that walks through generating .docx files with JavaScript or TypeScript via the docx npm package. The tutorial covers Document, Packer, Paragraph, TextRun, Table, ImageRun, headers, footers, hyperlinks, table of contents, page orientation, borders, and tab stops, with explicit warnings about formatting pitfalls that corrupt files. Developers reach for DOCX when they need code-driven Word exports—reports, contracts, or templated documents—instead of hand-editing layouts. Setup assumes docx is installed globally or via npm install -g docx.

  • Generates .docx files with JavaScript/TypeScript using the docx library
  • Supports Paragraph, TextRun, Table, ImageRun, TableOfContents, Header, Footer, Hyperlinks and PageBreak
  • Enforces correct line-break pattern using separate Paragraph elements instead of \n
  • Works in both Node.js (toBuffer + fs.writeFileSync) and browser (toBlob) environments
  • Includes 20+ formatting controls: alignment, spacing, borders, shading, headings, footnotes and page orientation

Docx by the numbers

  • 875 all-time installs (skills.sh)
  • +6 installs in the week ending Aug 2, 2026 (Skillselion tracking)
  • Ranked #292 of 1,879 Documentation skills by installs in the Skillselion catalog
  • Security screen: HIGH risk (skills.sh audit)
  • Data as of Aug 3, 2026 (Skillselion catalog sync)
npx skills add https://github.com/ailabs-393/ai-labs-claude-skills --skill docx

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs875
repo stars432
Security audit1 / 3 scanners passed
Last updatedNovember 11, 2025
Repositoryailabs-393/ai-labs-claude-skills

How do you generate formatted Word documents from JavaScript?

Programmatically generate polished, formatted Word documents from code without manual layout work.

Who is it for?

Developers building Node.js or TypeScript apps that must export polished Word documents programmatically rather than through manual Word editing.

Skip if: Developers who only need PDF generation, plain-text exports, or Google Docs API integration without .docx output.

When should I use this skill?

The user asks to create, format, or export a Word .docx file from JavaScript, TypeScript, or Node.js code.

What you get

Valid .docx files with paragraphs, tables, images, headers, footers, hyperlinks, and table-of-contents structure produced by code.

  • .docx files
  • document generation scripts

Files

SKILL.mdMarkdownGitHub ↗

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

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

// 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

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

Related skills

FAQ

Which library does the DOCX skill use?

The DOCX skill uses the docx npm package for JavaScript and TypeScript. Install it globally with npm install -g docx, then compose documents with Document, Paragraph, TextRun, Table, Packer, and related APIs.

What docx elements does the DOCX skill cover?

The DOCX skill covers paragraphs, text runs, tables, images, headers, footers, external and internal hyperlinks, table of contents, page orientation, borders, tab stops, and alignment. It also documents common pitfalls that cause corrupted or misrendered files.

Is Docx safe to install?

skills.sh reports 1 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.