
Product
Introducing Manifest Alerts
Socket now detects supply chain risks in project manifests, starting with missing lockfiles that can make dependency installs non-reproducible.
@office-open/docx
Advanced tools
Generate, parse, and patch .docx documents with a declarative TypeScript API
Generate, parse, and patch .docx documents with a declarative TypeScript API. Works in Node.js and browsers.
# pnpm
pnpm add @office-open/docx
# npm
npm install @office-open/docx
# yarn
yarn add @office-open/docx
# bun
bun add @office-open/docx
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);
Check the demo folder for 100+ working examples covering every feature.
Performance vs original docx (9.6.1) package (higher ops/s is better, Windows 11 / Node 24).
Default = XML DEFLATE level 1 (SuperFast); media is split by type, matching MS Office Word — already-compressed formats (PNG/JPEG/GIF) are STOREd, the rest (EMF/WMF/BMP/TIFF/…) use DEFLATE level 1 (verified on a real MS Office file). All STORE = no compression ({ compression: { xml: 0, media: 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, media: 0 } });
Create + toBuffer (end-to-end)
| Scenario | Default sync | Default async | All STORE sync | All STORE async | docx |
|---|---|---|---|---|---|
| Simple (2p + 1 img) | 1,047 ops/s | 605 ops/s | 1,444 ops/s | 1,448 ops/s | 82 ops/s |
| Styled paragraphs (20) + 1 img | 1,133 ops/s | 593 ops/s | 1,610 ops/s | 1,679 ops/s | 89 ops/s |
| Table (10x5) | 1,695 ops/s | 785 ops/s | 4,144 ops/s | 3,928 ops/s | 239 ops/s |
| Full featured + 2 imgs | 769 ops/s | 439 ops/s | 785 ops/s | 814 ops/s | 57 ops/s |
Large Files — Create + toBuffer
| Scenario | Default sync | Default async | All STORE sync | All STORE async | docx |
|---|---|---|---|---|---|
| 2000 paragraphs + 20 images | 62.7 ops/s | 51.9 ops/s | 34.7 ops/s | 35.2 ops/s | 3.0 ops/s |
| 200x10 table | 261 ops/s | 218 ops/s | 271 ops/s | 271 ops/s | 36.3 ops/s |
| 20 sections x 100p + 40 images | 35.8 ops/s | 27.1 ops/s | 18.0 ops/s | 18.7 ops/s | 1.8 ops/s |
Large File (~100MB) — Mixed Content
500 styled paragraphs + 38 mixed-size images (1-5MB, 100MB total) + 50x10 table.
| Scenario | Default sync | Default async | All STORE sync | All STORE async | docx |
|---|---|---|---|---|---|
| Mixed (500p+38img+50x10) | 9.7 ops/s | 8.2 ops/s | 5.1 ops/s | 4.2 ops/s | 0.30 ops/s |
FAQs
Generate, parse, and patch .docx documents with a declarative TypeScript API
The npm package @office-open/docx receives a total of 1,265 weekly downloads. As such, @office-open/docx popularity was classified as popular.
We found that @office-open/docx demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Product
Socket now detects supply chain risks in project manifests, starting with missing lockfiles that can make dependency installs non-reproducible.

Research
/Security News
The trojanized extensions use TinyGo-compiled WebAssembly and Solana transaction memos to resolve command-and-control infrastructure.

Security News
Anthropic says the directive cited national security concerns over a narrow jailbreak, but offered no specific technical details.