当前位置: 首页 > news >正文

上海网站制作价格网络课程

上海网站制作价格,网络课程,定西地网站建设,网站加速服务首先前端导包,注意exportDocx的导包位置要修改成你自己的 import {exportDocx} from /utils/docUtil/docutil.js; import {addDays} from date-fns; import {listGongyi} from "/api/system/detail";然后新建一个测试按钮 <el-col :span"1.5"><…

首先前端导包,注意exportDocx的导包位置要修改成你自己的

import {exportDocx} from '@/utils/docUtil/docutil.js'; 
import {addDays} from 'date-fns';
import {listGongyi} from "@/api/system/detail";

然后新建一个测试按钮

 <el-col :span="1.5"><el-buttontype="warning"plainicon="el-icon-download"size="mini"@click="generateWordDoc">导出</el-button></el-col>

接下来是js文件

    generateWordDoc(row) {const ids = row.id || this.ids;//查找后台数据库封装数据find(ids).then(response => {console.log(response.data)const data = {form: response.data,list: response.data.aaZzcgPurchases}//模板文件位置在public文件夹里exportDocx('/caigoudan.docx', data, `caigoudan.docx`)});}

然后将下面这个docutil.js文件复制到项目中,我是复制在utils/docUtil中

import docxtemplater from 'docxtemplater';
import PizZip from 'pizzip';
import JSZipUtils from 'jszip-utils';
import {saveAs} from 'file-saver';/**导出docx,导出word@param { String } tempDocxPath 模板文件路径@param { Object } data 文件中传入的数据@param { String } fileName 导出文件名称*/
export const exportDocx = (tempDocxPath, data, fileName) => {// 读取并获得模板文件的二进制内容JSZipUtils.getBinaryContent(tempDocxPath, (error, content) => {// input.docx是模板。我们在导出的时候,会根据此模板来导出对应的数据// 抛出异常if (error) {throw error}// 创建一个JSZip实例,内容为模板的内容const zip = new PizZip(content)// 创建并加载docxtemplater实例对象const doc = new docxtemplater().loadZip(zip)// 设置模板变量的值doc.setData({...data.form,list: data.list})try {// render the document (replace all occurences of {first_name} by John, {last_name} by Doe, ...)doc.render()} catch (error) {const e = {message: error.message,name: error.name,stack: error.stack,properties: error.properties}console.log({error: e})// The error thrown here contains additional information when logged with JSON.stringify (it contains a property object).throw error}const out = doc.getZip().generate({type: 'blob',mimeType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'}) // Output the document using Data-URIsaveAs(out, fileName)})
}

最后新建一个word模板文件,保存的格式要是docx才行哦
例如:
在这里插入图片描述
只要数据是集合,就得是{#list} 开头{/list}结尾
如果还有其他的集合,则自己修改data的值,记得配合修改:(自己研究一下立马就懂了)
另外自己的模板如果不弄页眉页脚的话,第二页是不显示页眉页脚的,所以要注意
在这里插入图片描述

注意,此模板文件必须放在项目中的public文件夹下 !!!

http://www.ds6.com.cn/news/111490.html

相关文章:

  • dw如何做网站关键词排名优化网站
  • ps网站轮播图怎么做星链seo管理
  • html5网站建设方案软件定制开发公司
  • 凡科网站怎么做建站网络营销的概念及内容
  • 乔柘云智能建站最佳搜索引擎
  • 北京网站优化效果怎样一站式媒体发布平台
  • 高端品牌运动鞋seo咨询茂名
  • 山东网站建设比较好seo免费培训教程
  • wordpress制作官方网站怎么用手机制作网站
  • unn建站市场营销十大经典案例
  • 通辽网站制作公司论坛优化seo
  • 余姚网站建设报价泸州网站seo
  • 免费做网站平台做推广公司
  • 深圳一定火网站建设广州今日刚刚发生的新闻
  • 网站顶部广告素材企业网站模板设计
  • 兴化市政府网站城乡建设局新产品推广方案怎么写
  • 深圳市作网站的公司淄博网站优化
  • 自学网站建设和seo打开百度官网
  • asp.net做购物网站ip域名解析查询
  • 教你做美食的网站新平台推广赚钱
  • 做网站工作图淘宝seo是指什么
  • 中山网站制作定制百度推广代理加盟
  • 杭州营销型网站建设厦门人才网唯一官方网站
  • 邯郸房产网站广告接单平台有哪些
  • 网站导航条做多高国家职业技能培训学校
  • 营销型网站设计公司四川省人民政府
  • 深圳高端网站建设模版广告公司推广渠道
  • 织梦小说网站模板下载软文推广新闻发布
  • wordpress主题可以更改主页布局杭州seo按天计费
  • w3c网站怎么做网络做推广公司