| | |
| | | } |
| | | |
| | | try { |
| | | // 新版创建解析器的正确方式(无需 import AngularParser) |
| | | const parser = (tag, _variable) => { |
| | | return { |
| | | get(scope) { |
| | | if (scope[tag] !== undefined) { |
| | | return scope[tag] || ''; |
| | | } |
| | | // 处理特殊变量(如 $first) |
| | | if (tag.startsWith('$')) { |
| | | const varName = tag.slice(1); |
| | | return scope[varName] || ''; |
| | | } |
| | | return ''; |
| | | } |
| | | }; |
| | | }; |
| | | // 加载模板文件内容到 PizZip |
| | | const zip = new PizZip(content); |
| | | const doc = new Docxtemplater(zip, { |
| | |
| | | linebreaks: true, |
| | | }); |
| | | |
| | | // const parser = new AngularParser(); |
| | | // doc.setOptions({ parser }); |
| | | |
| | | |
| | | // 设置模板中的占位符数据 |
| | | doc.setData(data); |