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

28 lines
782 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-24 01:05:43 +00:00
{
children: [new TextRun("Heading wow!")],
text: "{{ table_heading_1 }}",
},
{
children: [new TextRun("#657")],
text: "{{ item_1 }}",
},
{
children: [new TextRun("Lorem ipsum paragraph")],
text: "{{ paragraph_replace }}",
},
2023-02-17 10:38:03 +00:00
],
2023-02-16 20:17:48 +00:00
}).then((doc) => {
2023-02-08 03:18:11 +00:00
fs.writeFileSync("My Document.docx", doc);
});