Skip to content
Skills Library
Programming · Building & coding

docx

/docx

The docx library generates Word (.docx) files from Node.js or the browser in code, with no Word installation: paragraphs, tables, images, headers, footers, page numbers and numbered or bulleted lists. Use when someone asks to "generate a Word document from data", "create a .docx report in Node", "build a contract or proposal as docx", or "add page numbers to a generated Word file".

Repository
skills ↗
Licence
Apache-2.0
Last repository change
25.10.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
2
Scripts
0
HTML comments
0
URLs in SKILL.md
1
Deprecation

No signals detected. Repository changed on 25.10.2026, without references to retired models or APIs.

Licence

Apache-2.0, otwarta: można używać i zmieniać, z zachowaniem licencji i informacji o zmianach.

What it does and when to use it

The docx library generates Word (.docx) files from Node.js or the browser in code, with no Word installation: paragraphs, tables, images, headers, footers, page numbers and numbered or bulleted lists. Use when someone asks to "generate a Word document from data", "create a .docx report in Node", "build a contract or proposal as docx", or "add page numbers to a generated Word file".

Triggers from the description

generate a Word document from datacreate a .docx report in Nodebuild a contract or proposal as docxadd page numbers to a generated Word file
Original author description

The docx library generates Word (.docx) files from Node.js or the browser in code, with no Word installation: paragraphs, tables, images, headers, footers, page numbers and numbered or bulleted lists. Use when someone asks to "generate a Word document from data", "create a .docx report in Node", "build a contract or proposal as docx", or "add page numbers to a generated Word file".

How it works

  1. Overview
  2. Instructions
  3. Examples
  4. Guidelines
Original SKILL.md headings · 128 lines, 754 words
SKILL.md preview
---
name: docx
description: >-
  The docx library generates Word (.docx) files from Node.js or the browser in code, with no Word installation: paragraphs, tables, images, headers, footers, page numbers and numbered or bulleted lists. Use when someone asks to "generate a Word document from data", "create a .docx report in Node", "build a contract or proposal as docx", or "add page numbers to a generated Word file".
license: Apache-2.0
compatibility: "Node.js 16+ or a modern browser; docx 9.x"
metadata:
  author: terminal-skills
  version: "1.1.0"
  category: documents
  repository: https://github.com/dolanmiu/docx
  tags: "docx, word, document, reports, office"
---

# docx

## Overview

`docx` (npm package, repository dolanmiu/docx, version 9.14.0 when checked on 2026-10-24) builds Word documents declaratively: you create a `Document` with sections, then serialise it with `Packer`. It writes new files; it does not edit existing ones. The examples below were run against 9.14.0 and produced a valid .docx.

## Instructions

```bash
npm install docx
```

Use ES modules (`"type": "module"` in package.json) so top-level `await` works, or wrap the code in an async function.

1. Build a `Document({ sections: [{ children: [...] }] })`. Section content is `Paragraph` and `Table` objects.
2. Serialise with `await Packer.toBuffer(doc)` (Node), `Packer.toBlob(doc)` (browser) or `Packer.toBase64String(doc)`.
3. Write the buffer with `fs.writeFileSync`.

Things that differ from older tutorials:

- `ImageRun` needs `type` (`"png"`, `"jpg"`, `"gif"`, `"bmp"` or `"svg"`; svg also needs a `fallback` image). Omitting it is a TypeScript error. Add `altText` for accessibility.
- Table cell colour is `shading: { type: ShadingType.CLEAR, fill: "1F4E79", color: "auto" }`. `fill` is the cell background; this form was run and produced a valid file.
- Lists are not automatic: declare a `numbering.config` entry (use `LevelFormat.DECIMAL` or `LevelFormat.BULLET`) and refer to it with `numbering: { reference, level }` on each paragraph.
- Use the `HeadingLevel` enum (`HeadingLevel.HEADING_2`), never a string cast to `any`.

## Examples

### Example 1: "Generate a monthly report with a table and page numbers"

```typescript
// report.ts
import {
  Document, Packer, Paragraph, TextRun, HeadingLevel, Table, TableRow, TableCell,
  WidthType, ShadingType, Footer, PageNumber, AlignmentType,
} from "docx";
import fs from "node:fs";

const cell = (text: string, head = false) =>
  new TableCell({
    shading: head ? { type: ShadingType.CLEAR, fill: "1F4E79", color: "auto" } : undefined,
    children: [new Paragraph({ children: [new TextRun({ text, bold: head, color: head ? "FFFFFF" : undefined })] })],
  });

const doc = new Document({
  sections: [{
    footers: {
      default: new Footer({
        children: [new Paragraph({
          alignment: AlignmentType.CENTER,
          children: [new TextRun({ children: ["Page ", PageNumber.CURRENT, " of ", PageNumber.TOTAL_PAGES] })],
        })],
      }),
    },
    children: [
      new Paragraph({ heading: HeadingLevel.HEADING_1, text: "Monthly Report" }),
      new Paragraph({ children: [new TextRun("Covers "), new TextRun({ text: "September 2026", bold: true }), new TextRun(". Figures are preliminary.")] }),
      new Table({
        width: { size: 100, type: WidthType.PERCENTAGE },
        rows: [
          new TableRow({ tableHeader: true, children: [cell("Plan", true), cell("Revenue", true), cell("Growth", true)] }),
          new TableRow({ children: [cell("Starter"), cell("$45,000"), cell("+12%")] }),
          new TableRow({ children: [cell("Growth"), cell("$32,000"), cell("+8%")] }),
        ],
      }),
    ],
  }],
});

fs.writeFileSync("report.docx", await Packer.toBuffer(doc));
```

Run `npx tsx report.ts`; the result is `report.docx` with a heading, a shaded header row that repeats on page breaks, and "Page 1 of 1" in the footer (Word fills the fields in when it opens the file).

### Example 2: "Add a logo, a confidentiality header and a numbered action list"

```typescript
// proposal.ts
import {
  Document, Packer, Paragraph, TextRun, ImageRun, Header, AlignmentType, LevelFormat, HeadingLevel,
} from "docx";
import fs from "node:fs";

const doc = new Document({
  numbering: {
    config: [
      { reference: "actions", levels: [{ level: 0, format: LevelFormat.DECIMAL, text: "%1.", alignment: AlignmentType.LEFT }] },
      { reference: "bullets", levels: [{ level: 0, format: LevelFormat.BULLET, text: "•", alignment: AlignmentType.LEFT }] },
    ],
  },
  sections: [{
    headers: {
      default: new Header({
        children: [new Paragraph({ alignment: AlignmentType.RIGHT, children: [new TextRun({ text: "Confidential", italics: true, color: "999999" })] })],
      }),
    },
    children: [
      new Paragraph({
        children: [new ImageRun({
          type: "png",
          data: fs.readFileSync("logo.png"),
          transformation: { width: 200, height: 60 },
          altText: { name: "logo", title: "Company logo", description: "Northwind Studio logo" },
        })],
      }),
      new Paragraph({ heading: HeadingLevel.HEADING_2, text: "Action items" }),
      ...["Review Q3 metrics", "Update pricing model", "Schedule team sync"].map(
        (item) => new Paragraph({ text: item, numbering: { reference: "actions", level: 0 } }),
      ),
      new Paragraph({ text: "Open question: renewal terms", numbering: { reference: "bullets", level: 0 } }),
    ],
  }],
});

fs.writeFileSync("proposal.docx", await Packer.toBuffer(doc));
```

The output has the logo at the top, a right-aligned grey "Confidential" header on every page, a numbered list 1.-3. and one bullet.

## Guidelines

- Pass real `Buffer` data to `ImageRun`; to embed a remote image, download it first and check the response is an image.
- Page-number fields are computed by Word on open; a viewer that does not recalculate fields may show them blank.
- For many repeated items, generate the `Paragraph`/`TableRow` arrays with `map` rather than building the XML by hand.
- To check output without Word, unzip the file (`unzip -p report.docx word/document.xml`) or open it in LibreOffice.
- Do not use this library to edit an existing .docx or to read one; use a parser for reading and a template-filling tool for edits.
-
Files in this package (2)
  • SKILL.md 6 KB
  • _scores.json 2 KB

Versions

RepositoryScoreLicence
This page · TerminalSkills/skills100Apache-2.0
rongxinzy/rongxinai100AGPL-3.0
mateaix/mateclaw100Apache-2.0
neromtoobad/creator-skills100MIT
okou-ai/okou-skills100MIT
openbmb/pilotdeck100AGPL-3.0
wrongstack/wrongstack100MIT
asgeirtj/system_prompts_leaks100CC0-1.0
asgeirtj/system_prompts_leaks100CC0-1.0

Database snapshot: 13.11.2026 · package version 5f4c305ff641 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 2 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100docx-generator
    Create, read, and edit Word (.docx) files - styles, tables, images, headers, and templates - using python-docx. Use whenever a deliverable must be a Word document.
  • 100doc-skill-docx
    Creates and edits Word documents with python-docx: styles, tables, headers, footers, track-changes-safe edits. Use when the user asks for docx document skill work, or mentions doc, skill, docx.
  • 100docx-official
    Generating Word documents programmatically with docx library in Node.js. Use when generating .docx reports, contracts, invoices, or any structured Word document from data.
  • 100wps-docx-writer
    Word文档生成。用python-docx生成各类Word文档, 支持标题、正文、表格、图片、页眉页脚等元素。 用于帮助用户生成Word文档。当用户提到Word、docx、文档时触发。 Word document generator using python-docx.
  • 90markdown-to-docx
    Convert markdown documents to professionally formatted Word (.docx) files. Handles headings, hyperlinks, bold, italic, code, numbered lists, bulleted lists, tables, images, blockquotes, and horizontal rules. Use when asked to 'convert to Word', 'export as docx', 'make a Word doc…
  • 100zepi-docx
    Read and edit Word documents with python-docx on the bundled runtime — styles, numbering, tables, headers and footers, page breaks, images, find-and-replace across runs, and merging documents. Use for any task whose input or output is a .docx file, including extracting text or…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.