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

秦皇岛企业建网站营业推广策略

秦皇岛企业建网站,营业推广策略,wordpress css 图片路径,wordpress子域名图床最近接了个活,需要根据表格数据和用户给定的文档模板,生成报告,因为没得后端,所以做了一个纯前端的生成报告并下载,现实如下: 纯前端根据页面或者后台数据,读取本地文档模板,填充数…

最近接了个活,需要根据表格数据和用户给定的文档模板,生成报告,因为没得后端,所以做了一个纯前端的生成报告并下载,现实如下:

纯前端根据页面或者后台数据,读取本地文档模板,填充数据后并导出

1、技术 vue3 + element-plus 或者 vue2 + element-ui
2、安装依赖

npm install docxtemplater
npm install pizzip
npm install file-saver

3、模板文件,以doc为例,放在本地public
在这里插入图片描述
4、具体代码实现(复制可用)

<!-- 前端实现,获取本地文档模板,在页面上根据数据,导出一个有数据的word -->
<template><el-table :data="tableData" style="width: 100%"><el-table-column label="Date" width="180"><template #default="scope"><div style="display: flex; align-items: center"><el-icon><timer /></el-icon><span style="margin-left: 10px">{{ scope.row.date }}</span></div></template></el-table-column><el-table-column label="Name" width="180"><template #default="scope"><el-popover effect="light" trigger="hover" placement="top" width="auto"><template #default><div>name: {{ scope.row.name }}</div><div>address: {{ scope.row.address }}</div></template><template #reference><el-tag>{{ scope.row.name }}</el-tag></template></el-popover></template></el-table-column><el-table-column label="Operations"><template #default="scope"><el-button size="small" @click="generateReport(scope.row)">生成报告</el-button><el-button size="small" @click="handleEdit(scope.$index, scope.row)">Edit</el-button><el-button  size="small"  type="danger"  @click="handleDelete(scope.$index, scope.row)">Delete</el-button></template></el-table-column></el-table>
</template><script setup>
// import Docxtemplater from 'docxtemplater'
// import PizZip from 'pizzip'
import { saveAs } from 'file-saver'const tableData = [{date: '2016-05-03',name: 'Tom',address: 'No. 189, Grove St, Los Angeles',},{date: '2016-05-02',name: 'Tom',address: 'No. 189, Grove St, Los Angeles',},{date: '2016-05-04',name: 'Tom',address: 'No. 189, Grove St, Los Angeles',},{date: '2016-05-01',name: 'Tom',address: 'No. 189, Grove St, Los Angeles',},
]
const handleEdit = (index,row ) => {console.log(index, row)
}
const handleDelete = (index, row) => {console.log(index, row)
}const generateReport = async (row) => {console.log(row)try {// 1. 加载Word模板文件console.log(window.origin)const response = await fetch('/mb.docx')const arrayBuffer = await response.arrayBuffer()// 2. 初始化docxtemplater(老版本)// const zip = new PizZip(arrayBuffer)// const doc = new Docxtemplater().loadZip(zip)//新const PizZip = require('pizzip');const Docxtemplater = require('docxtemplater');const zip = new PizZip(arrayBuffer);const doc = new Docxtemplater(zip);// 3. 准备模板数据(根据你的Word模板结构调整)let templateData = {title: '数据分析报告',name:row.name,date:row.date,address:row.address,}// 4. 渲染模板doc.render(templateData)// 5. 生成并下载文件const out = doc.getZip().generate({ type: 'blob' })saveAs(out, `数据分析报告_${new Date().getTime()}.docx`)} catch (error) {console.error('生成报告失败:', error)}
}
</script>

5、点击生成报告结果如下
在这里插入图片描述

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

相关文章:

  • 网站推广系统方案免费的网页模板网站
  • 做淘宝客网站一定要备案吗安卓aso
  • 维拓设计在北京排名成都seo的方法
  • 珠海建设局网站自己制作一个网页
  • 无锡定制网站建设陕西seo主管
  • 举报网站建设运行汇报国际新闻界期刊
  • 如何做网站动态图标seo服务
  • 网站动态和静态的区别瑞金网络推广
  • 网站开发是做啥的宁波厂家关键词优化
  • 网站运营和推广深圳关键词快速排名
  • 做中学网站下载爱城市网app官方网站
  • 做网站的html框架百度快速收录教程
  • 做网站放到百度上需要什么网络营销推广方案怎么写
  • 撰写网站策划书search搜索引擎
  • 大型资讯门户网站怎么做排名百度框架户开户渠道代理
  • 网站备案需要多长时间佛山快速排名seo
  • 做网站是用wordpress还是DW微信营销软件手机版
  • 站点推广百度一下了你就知道官网
  • 加强制度建设 信息公开 网站 专栏百度文库个人登录入口
  • 哪里有免费的网站自己做seo攻略
  • 公司网站app怎么做查询网站注册信息
  • wordpress网站基础知识百度文库网页版登录入口
  • 企业网站备案需要法人拍照吗十大广告公司排名
  • dedecms免费网站模板汕头seo按天付费
  • 可以做直播源的佛教网站怎么让百度收录
  • 北京网站建设 云智互联营销案例最新
  • 平面设计接单平台app深圳百度seo哪家好
  • 沈阳商城网站建设网页制作用什么软件做
  • 网站平台需要做无形资产吗 怎么做推广软文范文
  • 文明网站建设情况报告百度品牌专区怎么收费