diff --git a/demo/85-template-document.ts b/demo/85-template-document.ts index 0c95599e84..b4f674b967 100644 --- a/demo/85-template-document.ts +++ b/demo/85-template-document.ts @@ -36,6 +36,16 @@ patchDocument(fs.readFileSync("demo/assets/simple-template.docx"), { children: [new Paragraph("Lorem ipsum paragraph"), new Paragraph("Another paragraph")], text: "{{ paragraph_replace }}", }, + { + type: PatchType.PARAGRAPH, + children: [new TextRun("Delightful Header")], + text: "{{ header_adjective }}", + }, + { + type: PatchType.PARAGRAPH, + children: [new TextRun("replaced just as well")], + text: "{{ footer_text }}", + }, { type: PatchType.DOCUMENT, children: [ diff --git a/demo/assets/simple-template.docx b/demo/assets/simple-template.docx index c926191881..dab8b9e7c2 100644 Binary files a/demo/assets/simple-template.docx and b/demo/assets/simple-template.docx differ diff --git a/src/templater/from-docx.ts b/src/templater/from-docx.ts index 4117e04917..e380d9973e 100644 --- a/src/templater/from-docx.ts +++ b/src/templater/from-docx.ts @@ -41,7 +41,7 @@ export const patchDocument = async (data: InputDataType, options: PatchDocumentO for (const [key, value] of Object.entries(zipContent.files)) { const json = toJson(await value.async("text")); - if (key === "word/document.xml") { + if (key.startsWith("word/")) { for (const patch of options.patches) { const renderedParagraphs = findLocationOfText(json, patch.text); replacer(json, patch, renderedParagraphs);