mirror of
https://github.com/dolanmiu/docx.git
synced 2026-12-01 16:55:59 +01:00
docx/layout counted each list on its own, ignored w:lvlOverride, w:lvlJc, w:lvlRestart and w:isLgl, wrote "1" for a number format it couldn't write, and measured a number in its paragraph style's formatting, as text. Word's PDF of a new probe, word-lists, settles each, and the layout now follows it: - lists made from one definition count on from one another, and a list's own first number for a level starts that level there at its first paragraph of the level, once; a level a list gives starts at its own first number - a right-aligned number ends at the start of the first line, with the space after it, and a centred one is centred there; the text goes on from its end - w:lvlRestart and legal numbering, as the schema has them - a number is in its paragraph mark's formatting, but for its level's, and makes its line taller only above the baseline; the space after it is measured in Arial, as Word draws it Where Word hasn't shown what it does, the layout stops: formats it can't write, a level not counted yet that its list starts elsewhere, a centred number followed by a space, the tab after a right-aligned number at a stop Word hasn't been seen to use, picture bullets, Word 6 numbering and lists defined by list styles.
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);
});
Made with 💖
