mirror of
https://github.com/dolanmiu/docx.git
synced 2026-11-30 16:47:55 +01:00
* fix(layout): lay out rows that repeat their table's properties, split rows at multiple line spacing and overfull text boxes, as Word does estimatePageNumbers stopped at three things report templates have (#3912): - A row whose w:tblPrEx repeats the table's own w:tblW, w:tblLayout or w:tblInd. Properties that are the same as the table's change nothing, so only those that differ still stop the layout. - A cell's line at multiple spacing at the foot of a row that breaks across pages, where it fits only without the space below its text. word-split-rows-and-boxes.docx shows Word moves it to the next page, unlike in the body: 69 probes, with and without borders and above a cell's bottom margin, all now on Word's pages. - An inline VML text box of its own height whose text is taller than it. Word cuts the text off and keeps the box's height (OB1 in the same probe), so the box is laid out at its own height. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(layout): compare a row's table properties with the table's whatever order their attributes are in XML gives attributes no order, so a row's w:tblPrEx written with w:type before w:w is the same as the table's w:tblW written the other way round. The comparison now sorts each element's attributes first, as a text frame's are compared, rather than stopping the layout there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(layout): put the probe's text box shape type before whichever box ONLY leaves first The shape type was added to OB1a's box, so a run with ONLY=OB1b wrote a box referring to a shape type the document didn't declare. It now goes before the first box in the document, whichever that is. A full run writes the same document as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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 💖
