
Company News
Andrew Becherer Joins Socket as Chief Information Security Officer
Socket’s first CISO brings deep experience securing high-growth SaaS companies as open source supply chain threats accelerate.
@office-open/docx
Advanced tools
Easily generate .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.
Easily generate .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.
# Install with npm
$ npm install @office-open/docx
# Install with pnpm
$ pnpm add @office-open/docx
import { Document, Paragraph, TextRun, Packer } from "@office-open/docx";
import { writeFileSync } from "node:fs";
const doc = new Document({
sections: [
{
children: [
new Paragraph({
children: [
new TextRun("Hello World"),
new TextRun({
text: " - Bold text",
bold: true,
}),
],
}),
],
},
],
});
const buffer = await Packer.toBuffer(doc);
writeFileSync("My Document.docx", buffer);
Check the demo folder for 100+ working examples covering every feature.
Performance comparison against original docx (9.6.1) package (Windows 11 / Node 22):
Object Creation (no pack)
| Scenario | @office-open/docx | docx | Speedup |
|---|---|---|---|
| Simple document (2 paragraphs) | 20.0K ops/s | 6.2K ops/s | 3.2x |
| Styled paragraphs (20 paragraphs) | 11.4K ops/s | 4.6K ops/s | 2.5x |
| Table (10x5 cells) | 10.1K ops/s | 3.7K ops/s | 2.7x |
| Full featured (header/footer/headings/table/paragraphs) | 5.5K ops/s | 2.8K ops/s | 2.0x |
Create + toBuffer (end-to-end)
Both libraries use DEFLATE compression.
| Scenario | @office-open/docx | docx | Speedup |
|---|---|---|---|
| Simple document (2 paragraphs) | 388 ops/s | 194 ops/s | 2.0x |
| Styled paragraphs (20 paragraphs) | 402 ops/s | 232 ops/s | 1.7x |
| Table (10x5 cells) | 463 ops/s | 238 ops/s | 1.9x |
| Full featured (header/footer/headings/table/paragraphs) | 346 ops/s | 179 ops/s | 1.9x |
Large Files — Create + toBuffer
| Scenario | @office-open/docx | docx | Speedup |
|---|---|---|---|
| 2000 paragraphs | 42.2 ops/s | 27.7 ops/s | 1.5x |
| 200×10 table | 77.4 ops/s | 37.3 ops/s | 2.1x |
| 20 sections × 100 paragraphs | 47.0 ops/s | 30.9 ops/s | 1.5x |
Large File (~100MB) — Mixed Content
2000 paragraphs + 200 unique images (500KB each) + 100×10 table. Speedup is vs docx.
| Method | Speed | Speedup |
|---|---|---|
| @office-open/docx (sync) | 0.36 ops/s | 1.2x |
| @office-open/docx (async) | 0.40 ops/s | 1.3x |
| docx | 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 618 weekly downloads. As such, @office-open/docx popularity was classified as not 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.

Company News
Socket’s first CISO brings deep experience securing high-growth SaaS companies as open source supply chain threats accelerate.

Company News
Replit is integrating Socket Firewall into its AI-powered development experience to help protect builders from malicious open source packages.

Security News
npm confirmed a tooling bug incorrectly marked several one-character packages as security holders and said it was working on a rollback.