mirror of
https://github.com/dolanmiu/docx.git
synced 2026-11-30 16:47:55 +01:00
* feat(layout): break the text of cells merged down rows with the row that crosses the page, as Word does Word's PDF of word-probes.docx (U4a, U4b) showed that the text of a cell merged down rows starts at the top of the merge's first row and goes down across its rows, so the row of them that crosses the page breaks it, as far down the page as its lines go. The rest goes on from the top of the merge's rows on the next page. docx/layout stopped at any row with merged cells that broke across pages, and at a merge that didn't fit with its cell's text. Where Word hasn't shown what it does, it still stops: text that goes on across a page break between the merge's rows, or across more than two pages, and text with a footnote, or from a table's header rows, that goes on across pages. A row of a set height taller than its text already moved whole (#3616), as U4e to U4g show; a test now covers U4f, whose text doesn't fit either. Adds the merged-cells-across-pages layout demo. * docs(layout): say what the merged-cells demo keeps to for LibreOffice, as checked
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 💖
