DOCX

@office-open/docx

Generate .docx documents with a declarative TypeScript API

Installation

pnpm add @office-open/docx

Quick Start

import { Document, Packer, Paragraph, TextRun } from "@office-open/docx";

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

const buffer = await Packer.toBuffer(doc);

Main Components

ComponentDescription
DocumentRoot document container with sections and properties
ParagraphText paragraph with formatting, alignment, and spacing
TextRunInline text with font, size, color, and style
Table, TableRow, TableCellStructured tables with merged cells and borders
ImageRunEmbedded images with transformation and positioning
ChartRunBar, line, pie, area, and scatter charts
SmartArtRunPredefined SmartArt diagrams
Header, FooterSection headers and footers
FootnoteReferenceRunFootnotes and endnotes
TableOfContentsAuto-generated table of contents
BookmarkInternal bookmarks and cross-references
Math, MathRunMathematical equations
StylesDeclarative style definitions

Export Formats

MethodReturnsUse Case
Packer.toBuffer(doc)Uint8ArrayNode.js file I/O
Packer.toBlob(doc)BlobBrowser downloads
Packer.toBase64String(doc)stringData URLs, API payloads
Packer.toString(doc)stringDebugging, inspection
Packer.toStream(doc)ReadableStreamStreaming large files
Copyright © 2026