引入JS

word模板

用word制作模板,例如:

模板内容:

编写代码

 exportWord() {
      const { baseInfo } = this.form
      JSZipUtils.getBinaryContent('index.docx', (error, content) => {
        console.log('error = ', error, content)
        const zip = new PizZip(content)
        const doc = new docxtemplater()
        doc.loadZip(zip)
        doc.setData(baseInfo)
        try {
          doc.render()
        } catch (error) {
          const e = {
            message: error.message,
            name: error.name,
            stack: error.stack,
            properties: error.properties
          }
          throw error
        }
        const out = doc.getZip().generate({
          type: 'blob',
          mimeType:
            'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
        })
        saveAs(out, '个人电子档案.docx')
      })
    },

 

Logo

前往低代码交流专区

更多推荐