// HTML in a template (issue #2632): patchDocument replaces a placeholder's paragraph with HTML's paragraphs, lists and // tables, and a placeholder in a paragraph with inline HTML. See docs/usage/html.md. import * as fs from "fs"; import { patchDocument, PatchType } from "docx"; import { htmlToContent, htmlToRuns } from "docx/html"; patchDocument({ outputType: "nodebuffer", data: fs.readFileSync("./demo/assets/simple-template.docx"), patches: { name: { type: PatchType.PARAGRAPH, children: [...htmlToRuns("Ada Lovelace")] }, paragraph_replace: { type: PatchType.DOCUMENT, children: [ ...htmlToContent(`

The report, written in an editor:

  1. Sales were up 12%
  2. Costs rose fell
RegionSales
EMEA1,200
`), ], }, }, }).then((buffer) => { fs.writeFileSync("My Document.docx", buffer); });