Files
docx-js/demo/85-template-document.ts

16 lines
437 B
TypeScript
Raw Normal View History

2023-02-08 03:18:11 +00:00
// Simple template example
// Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
2023-02-18 20:36:24 +00:00
import { patchDocument, TextRun } from "../build";
2023-02-08 03:18:11 +00:00
2023-02-16 20:17:48 +00:00
patchDocument(fs.readFileSync("demo/assets/simple-template.docx"), {
2023-02-17 10:38:03 +00:00
patches: [
{
2023-02-18 20:36:24 +00:00
children: [new TextRun("John Doe")],
2023-02-17 10:38:03 +00:00
text: "{{ name }}",
},
],
2023-02-16 20:17:48 +00:00
}).then((doc) => {
2023-02-08 03:18:11 +00:00
fs.writeFileSync("My Document.docx", doc);
});