Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@office-open/docx

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@office-open/docx

Generate, parse, and patch .docx documents with a declarative TypeScript API

edge
latest
Source
npmnpm
Version
0.9.0
Version published
Weekly downloads
693
-59.83%
Maintainers
1
Weekly downloads
 
Created
Source

@office-open/docx

npm version npm downloads npm license

Generate, parse, and patch .docx documents with a declarative TypeScript API. Works in Node.js and browsers.

Features

  • 📄 Document Generation — Create Word documents with sections, headers, footers, and page numbers
  • ✍️ Paragraphs & Text — Rich text support with bold, italic, underline, strikethrough, and more
  • 📊 Tables — Full table support with merged cells, borders, and styles
  • 🖼️ Images — Inline and floating images with sizing, positioning, and wrapping
  • 🔗 Hyperlinks — External and internal hyperlinks with custom styling
  • 📑 Headers & Footers — First, last, even/odd page headers and footers
  • 📋 Lists — Numbered and bulleted lists with multiple levels and custom formats
  • 🎨 Styles — Paragraph, character, and table styles with inheritance
  • 📖 Table of Contents — Auto-generated table of contents with custom styling
  • 📝 Footnotes & Endnotes — Comprehensive footnote and endnote support
  • 📈 Charts — Bar, line, pie, area, and scatter charts with customization
  • 🔢 Math Equations — Full mathematical equation support via Office MathML (OMML)
  • 🧩 SmartArt — Built-in SmartArt graphic generation
  • 📚 Bibliography — Source management and citation support
  • 💬 Comments — Document comments with author and date tracking
  • 📝 Track Revisions — Insertions, deletions, and formatting changes
  • 📋 Content Controls — Structured document tags (SDT) for form-like documents
  • 📦 Text Boxes — Floating text boxes with content and styling
  • ☑️ Checkboxes — Form checkbox support in documents
  • 🖌️ DrawingML — Shapes with fills, shadows, effects, and transformations
  • 🔤 Custom Fonts — Font embedding and custom font tables
  • 🔧 Template Patching — Patch existing DOCX templates via placeholder replacement
  • ⚙️ Settings — Comprehensive document settings and compatibility options

Installation

# pnpm
pnpm add @office-open/docx

# npm
npm install @office-open/docx

# yarn
yarn add @office-open/docx

# bun
bun add @office-open/docx

Quick Start

import { generateDocument } from "@office-open/docx";
import { writeFileSync } from "node:fs";

const buffer = await generateDocument({
  sections: [
    {
      children: [
        {
          paragraph: {
            children: ["Hello World", { text: " - Bold text", bold: true }],
          },
        },
      ],
    },
  ],
});

writeFileSync("My Document.docx", buffer);

Examples

Check the demo folder for 100+ working examples covering every feature.

Benchmark

Performance vs original docx (9.6.1) package (higher ops/s is better, Windows 11 / Node 24).

Default = XML DEFLATE level 1 (SuperFast, matching MS Office) + media STORE. All STORE = no compression ({ compression: { xml: 0 } }). docx (async only) always uses DEFLATE for ALL entries including images (via JSZip, hardcoded, no STORE option).

// Default (matches MS Office)
await generateDocument(options);
// All STORE (no compression)
await generateDocument(options, { compression: { xml: 0 } });

Create + toBuffer (end-to-end)

ScenarioDefault syncDefault asyncAll STORE syncAll STORE asyncdocx
Simple (2p + 1 img)827 ops/s493 ops/s1,392 ops/s1,483 ops/s89 ops/s
Styled paragraphs (20) + 1 img856 ops/s497 ops/s1,558 ops/s1,574 ops/s95 ops/s
Table (10x5)1,390 ops/s647 ops/s3,786 ops/s3,707 ops/s217 ops/s
Full featured + 2 imgs547 ops/s364 ops/s851 ops/s819 ops/s56 ops/s

Large Files — Create + toBuffer

ScenarioDefault syncDefault asyncAll STORE syncAll STORE asyncdocx
2000 paragraphs + 20 images29.4 ops/s31.5 ops/s27.5 ops/s32.2 ops/s2.7 ops/s
200x10 table298 ops/s233 ops/s313 ops/s317 ops/s39.6 ops/s
20 sections x 100p + 40 images18.1 ops/s17.3 ops/s17.4 ops/s18.4 ops/s1.7 ops/s

Large File (~100MB) — Mixed Content

500 styled paragraphs + 38 mixed-size images (1-5MB, 100MB total) + 50x10 table.

ScenarioDefault syncDefault asyncAll STORE syncAll STORE asyncdocx
Mixed (500p+38img+50x10)3.9 ops/s3.9 ops/s4.4 ops/s4.0 ops/s0.31 ops/s

License

Keywords

clippy

FAQs

Package last updated on 12 Jun 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts