deno.land / x / docx@8.5.0 / demo / 89-template-document.ts

89-template-document.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Patch a document with patches
import * as fs from "fs";import { IPatch, patchDocument, PatchType, TextRun } from "docx";
export const font = "Trebuchet MS";export const getPatches = (fields: { [key: string]: string }) => { const patches: { [key: string]: IPatch } = {};
for (const field in fields) { patches[field] = { type: PatchType.PARAGRAPH, children: [new TextRun({ text: fields[field], font })], }; }
return patches;};
const patches = getPatches({ salutation: "Mr.", "first-name": "John",});
patchDocument(fs.readFileSync("demo/assets/simple-template-3.docx"), { patches,}).then((doc) => { fs.writeFileSync("My Document.docx", doc);});
docx

Version Info

Tagged at
4 months ago