Files
docx/docs
Dolan a871df8a25 docs(layout): leave updateFields off in the page-number demos, so Word opens them without asking (#3676)
* docs(layout): leave updateFields off in the page-number demos, so Word opens them without asking

The table-of-contents-page-numbers and template-page-numbers demos still set
features: { updateFields: true }, from before docx/layout wrote page references
and tables of contents clean, so Word asked to update the fields when it opened
them. They now leave it off, and show the page numbers docx/layout wrote.

patchDocument keeps a template's settings, w:updateFields among them, so the
Templates section of docs/usage/layout.md now says to leave it off in the
template.

* docs(demo): set updateFields: false explicitly in every demo that set it

The maintainer asked for every demo to say updateFields: false rather than
leave the option out. demo/fields/table-of-contents.ts now says so too, with
a comment that its table of contents stays empty until the reader updates
it in Word.

* docs(demo): write the fields demo's table of contents with docx/layout, so Word opens it without asking

The maintainer chose to switch demo/fields/table-of-contents.ts to
docx/layout: with pageNumbers: estimatePageNumbers its table of contents is
written with its page numbers and clean, and with updateFields off Word
shows it as it is written and doesn't ask to update the fields.

* docs(layout): say Word opens a filled-in template without asking only as it does a document whose fields are written clean

CodeRabbit read the Templates sentence as unconditional. It now points to
what still makes Word ask.
2026-10-04 13:15:00 +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 💖