mirror of
https://github.com/dolanmiu/docx.git
synced 2026-11-30 16:47:55 +01:00
* feat(layout): lay out table borders of different styles that meet, and borders beside space between cells, as Word does Word's PDF of word-stops-table-borders.docx (lay-stops2's batch) settles the table border stops of the work's line 6: - Where two cells' borders meet, Word draws the heavier, by the weights MS-OI29500 gives for 17.4.66, but makes room for the wider of the two whichever it draws (TB1 to TB3; TB3d: a dotted border of 1.5 points below a single one of half a point takes 1.5 points, below the single one Word draws). Beside text, where Word draws the narrower and half the wider is more than the margin, which it keeps the text from hasn't been seen, so that still stops. - Wave and 3D borders take their room at each width Word offers (TB4a to TB4v). - With space between cells, each cell's borders left and right of it take their width from its text, and the table's none (TB5a to TB5l). A row's own space is the table's, at its edges too (TB6c, TB6d), and space given as a share of the table's width is none (TB6a, TB6b). Where such a table breaks across pages, its bottom border is below the last of it on the page and its top border above the rest of it on the next, between rows and in them (TB7a to TB7c). Paragraph and run borders with a medium or large gap take the room they take beside a table's cells (word-table-formats.docx BS, word-stops-text.docx PB4b). * fix(layout): leave a deleted row's space between cells out of the rows' comparison A deleted row takes no room, nor does the space around it (word-tracked-tables.docx MK14h), so a table whose kept rows all have the same space between their cells no longer stops for a deleted row with other space, and its space is the first kept row's. * fix(layout): stop at a row's own borders in a table with space between its cells A row's own table borders (w:tblPrEx), which #3686 gives its cells, meet space between cells, whose table borders go around the space (word-stops-table-borders.docx TB5). Where Word puts a row's own hasn't been seen, so the layout stops there rather than guessing.
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 💖
