Closed qinmcdio closed 3 years ago
Environment
Runner : Node.JS template2.docx
How to reproduce my problem :
My template is the following : (Upload the docx file here inside github, which you have to name template.zip (github doesn't accept the docx extension))
With the following js file :
const expressions = require('angular-expressions'); const fs = require('fs'); const path = require('path'); const Docxtemplater = require('docxtemplater'); const JSZip = require('jszip'); // Load the docx file as a binary const templatePath = path.join(__dirname, 'template2.docx'); const content = fs .readFileSync(templatePath, 'binary'); const reportData = { chapters: [{ chapter: 'a' }, { chapter: 'b' }, { chapter: 'c' }] }; const docxTemplate = new Docxtemplater(); const zip = new JSZip(content); const angularParser = (tag) => { const expr = expressions.compile(tag); return { get: expr }; }; docxTemplate.loadZip(zip); docxTemplate.setOptions({ parser: angularParser }); docxTemplate.setData(reportData); docxTemplate.render(); const buf = docxTemplate.getZip() .generate({ type: 'nodebuffer' }); fs.writeFileSync(`${__dirname}/output.docx`, buf);
What is the error that you get ?
I don't understand what is the issue here.
output.docx I check the directory then find the page is wrong, can I use loop to generate directory?
Environment
Runner : Node.JS template2.docx
How to reproduce my problem :
My template is the following : (Upload the docx file here inside github, which you have to name template.zip (github doesn't accept the docx extension))
With the following js file :