mirror of
https://github.com/dolanmiu/docx.git
synced 2026-12-01 16:55:59 +01:00
* feat(layout): lay out tracked changes as Word shows them in balloons and Simple Markup A paragraph whose mark is deleted joins the next, in the next one's formatting, a deleted section break leaves its section to the next, deleted rows take no room, and a deleted footnote is still counted. Word sizes a table's columns by its deleted rows and text all the same. Where Word hasn't been seen, the layout stops. * fix(layout): read a deleted row of a table laid out fixed as the layout reads deleted runs, keeping its bookmarks It was read as Word sizes columns, with its deleted text shown, so a deleted tab or break in it stopped its paragraph and lost its bookmarks, though nothing sizes a fixed table's columns by it. * fix(layout): say whether MK11g's deleted header row is on the table's first page and on the next, apart The probe reader said the header was shown if it was on any page, so it couldn't tell the table's first page from a repeat on the next. * test(layout): expect a footnote reference's number in its run's font, as #3641 writes it * fix(layout): stop at a field only part of which is deleted in a tracked change A deleted run's field characters were dropped, so a deletion of a field's end or separator, and not its start, left the field open, and the text after it was left out without a stop. They now keep their place on the field stack: a field deleted whole is left out, as Word shows it, and one deleted only in part stops the layout. * test(layout): number notes read again to size a table's columns as #3638 numbers them * fix(layout): stop at a deleted footnote reference with a mark of its own, as at one not deleted Word may not count such a note in the numbers of the others, so counting it when its reference is deleted could number the footnotes after it one too high without a stop.
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 💖
