From 4fe6c5ac4bc2b7fa9c9c71bb52d9df3e8b13bd7c Mon Sep 17 00:00:00 2001 From: zhouwx <1175765986@qq.com> Date: 星期二, 15 七月 2025 10:11:45 +0800 Subject: [PATCH] 修改 --- src/utils/exportWord.js | 20 ++++++++++++++++++++ 1 files changed, 20 insertions(+), 0 deletions(-) diff --git a/src/utils/exportWord.js b/src/utils/exportWord.js index 3ba3d7b..6c7fbe1 100644 --- a/src/utils/exportWord.js +++ b/src/utils/exportWord.js @@ -23,6 +23,22 @@ } 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, { @@ -30,6 +46,10 @@ linebreaks: true, }); + // const parser = new AngularParser(); + // doc.setOptions({ parser }); + + // 设置模板中的占位符数据 doc.setData(data); -- Gitblit v1.9.2