From 56c9b08d1c1c978ee3933d074b4d020026686915 Mon Sep 17 00:00:00 2001 From: zhouwx <1175765986@qq.com> Date: 星期三, 09 七月 2025 14:26:30 +0800 Subject: [PATCH] 修改 --- src/utils/exportWord.js | 19 +++++++++++++++++++ 1 files changed, 19 insertions(+), 0 deletions(-) diff --git a/src/utils/exportWord.js b/src/utils/exportWord.js index e0ee5c1..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,9 @@ linebreaks: true, }); + // const parser = new AngularParser(); + // doc.setOptions({ parser }); + // 设置模板中的占位符数据 doc.setData(data); -- Gitblit v1.9.2