npm i jszip@^2.6.1
npm i file-saver@^2.0.2
npm i docxtemplater@^3.17.6
npm i jszip-utils@^0.1.0
npm i pizzip
npm i open-docxtemplater-image-module
导出所含依赖对应版本
docxtemplater使用最新的版本3.5的会导致\n,\r\n,失效,无法实现换行
公共组件创建引用相应的依赖
<ExportDoc ref="newReport" style="float: right;margin-left:15px" :export-title="报告表'" export-name="报告表.doc" import-url="/newReport.docx" @reportClick="newReportClick" />
// 调用
async newReportClick () {
const result = await Model.getByDwbm({
pg: pg
})
if (!result.data) return this.$message.warning('请先保存数据后,再执行操作!')
var newObj = JSON.parse(JSON.stringify(this.originData))
const newList = {
...newObj,
tcDwmc: JSON.parse(this.$route.query.curOrg).pgbm
}
const fileName = `评估表`
const data = {
bindData: newList
}
if (this.downloadList.includes(fileName)) {
if (!window.confirm('您刚刚已经下载过改文件了哦,需要重新下载吗?')) {
return false
}
}
this.$refs.newReport.exportWord(data)
// 把已下载的表名存入已下载列表中
this.downloadList.push(fileName)
}
docx文档使用的模板语法,if else 判断
![59_1$A26PP00_A__RJ1LNL.png