Files
docx/docs
DolanandClaude Opus 5.5 9397bbd549 feat: write Word's Caption style, and document captions and cross-references (#557) (#3813)
Word gives the captions it inserts the paragraph style "caption", and docx
didn't write it, so a paragraph with `style: "Caption"` came out in Normal:
Word drops a style the document doesn't define. docx now writes the style
as Word writes it when it inserts a caption (small italic text in the
theme's second dark color, with space after), and `styles.default.caption`
changes it. A Caption style in paragraphStyles or externalStyles still takes
its place.

A new docs page shows captions with SequentialIdentifier, their numbers
written by docx/layout, cross-references to them with a bookmark and
NumberedItemReference, and a table of figures, none of which the docs
covered.


Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 16:22:38 +01:00
..
2020-09-05 18:40:40 +01:00
2020-09-05 18:51:50 +01:00

Welcome to docx

What is docx?

docx is a TypeScript/JavaScript library for generating Word documents (.docx files) programmatically. It provides a declarative API that works seamlessly in both Node.js and browser environments.

Why docx?

  • Declarative API - Define what you want (objects/config), not how to build it step-by-step
  • TypeScript First - Full type definitions with IntelliSense support
  • Universal - Works in Node.js, browsers, and serverless environments
  • No Dependencies - Zero external runtime dependencies
  • Full Featured - Tables, images, shapes, charts, headers, footers, styles, and more

Quick Navigation

I want to... Go to...
Get started quickly Quickstart Guide
Learn a specific feature Usage Guides
See working examples Demo Files
Browse the API API Documentation
Modify existing documents Patcher

Installation

npm install --save docx

Then you can require or import as usual:

const docx = require("docx");
import * as docx from "docx";
// or
import { Document, Packer, Paragraph, TextRun } from "docx";

Shapes, watermarks and charts come with the package too, from docx/shapes, docx/watermarks and docx/charts:

import { ShapeRun } from "docx/shapes";
import { TextWatermark } from "docx/watermarks";
import { ChartRun } from "docx/charts";

Basic Usage

import * as fs from "fs";
import { Document, Packer, Paragraph, TextRun } from "docx";

const doc = new Document({
    sections: [
        {
            children: [
                new Paragraph({
                    children: [
                        new TextRun("Hello World"),
                        new TextRun({
                            text: " - Bold text",
                            bold: true,
                        }),
                    ],
                }),
            ],
        },
    ],
});

Packer.toBuffer(doc).then((buffer) => {
    fs.writeFileSync("My Document.docx", buffer);
});

clippy the assistant


Made with 💖