// HTML as a document's content (issue #2632): a rich-text editor's HTML, with its headings, formatting, lists, a // table, an image, links, math and a page break, in a document's body, and some inline HTML in its header and a // paragraph of its own. See docs/usage/html.md. // cspell:ignore EMEA import * as fs from "fs"; import { Document, Header, Packer, Paragraph, TextRun } from "docx"; import { htmlToContent, htmlToRuns } from "docx/html"; const html = `
Sales were up 12%, led by EMEA. Returns were
flat, and costs rose fell.
Close the quarter
Plan the next one
| Region | Q2 | Q3 |
|---|---|---|
| EMEA | 1,050 | 1,200 |
| APAC | 880 | 900 |
| Total | 2,100 | |

The best quarter since the company started.
Growth, compounded: .
total = sum(sales)
Back to the appendix.
`; const doc = new Document({ sections: [ { headers: { default: new Header({ children: [new Paragraph({ children: [...htmlToRuns("Quarterly report · Draft")] })], }), }, children: [ ...htmlToContent(html, { images: { "logo.png": fs.readFileSync("./demo/assets/html/logo.png") } }), new Paragraph({ children: [new TextRun("Written by docx: "), ...htmlToRuns("bold and italic in a paragraph of its own.")], }), ], }, ], }); Packer.toBuffer(doc).then((buffer) => { fs.writeFileSync("My Document.docx", buffer); });