open-xml-templating / docxtemplater

Generate docx, pptx, and xlsx from templates (Word, Powerpoint and Excel documents), from Node.js or the browser. Demo: https://www.docxtemplater.com/demo. #docx #office #generator #templating #report #json #generate #generation #template #create #pptx #docx #xlsx #react #vuejs #angularjs #browser #typescript #image #html #table #chart
https://www.docxtemplater.com
Other
3.01k stars 347 forks source link

auto generated directory has error link to page #563

Closed qinmcdio closed 3 years ago

qinmcdio commented 3 years ago

Environment

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);
edi9999 commented 3 years ago

What is the error that you get ?

I don't understand what is the issue here.

qinmcdio commented 3 years ago

output.docx I check the directory then find the page is wrong, can I use loop to generate directory?