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

网站建设下载百度2018旧版下载

网站建设下载,百度2018旧版下载,雄安网建 网站建设,给客户做网站最近接了个活,需要根据表格数据和用户给定的文档模板,生成报告,因为没得后端,所以做了一个纯前端的生成报告并下载,现实如下: 纯前端根据页面或者后台数据,读取本地文档模板,填充数…

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

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

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.hkea.cn/news/71404/

相关文章:

  • 有一个做场景动画的网站山东seo费用多少
  • 阿里云服务器的网站备案流程图营销推广有哪些形式
  • 做宣传用什么网站好手游推广平台有哪些
  • 免费全国网站在线客服软件新手电商运营从哪开始学
  • 0317网站建设怎么建个网站
  • 做网站做电脑版还是手机版好电话营销
  • 深圳网站建设 设计搜索引擎的工作原理是什么?
  • 在线网站设计百度收录查询方法
  • 最新体育新闻足球百度seo收费
  • 手机网站做跳转好吗个人在百度上发广告怎么发
  • 民宿网站的建设最近热搜新闻事件
  • 企业网站建设的核心是企业推广视频
  • 设计素材网站蜂产品推广文章
  • wordpress站点描述seo哪个软件好
  • 澳门服务器做网站需要备案吗百度ai人工智能平台
  • 做化验的在哪个网站里投简历河南网站关键词优化
  • 百度网址大全网站大全网络整合营销方案ppt
  • 海阳市建设工程交易中心网站品牌推广的作用
  • 江西省住房和城乡建设网站成都网站优化seo
  • java资源网站云优化
  • 小程序源码大全网络seo关键词优化技巧
  • 服务佳的小企业网站建设ip子域名大全
  • 网页与制作唐山seo推广公司
  • 自己做的网站怎么弄到网上在线网页制作
  • 电商网站 设计方案百度的排名规则详解
  • 福建省建设厅网站余外链链接平台
  • 广告营销网站市场推广方案
  • 徐州企业做网站软文是什么文章
  • 网站代码备份如何优化seo
  • 百度网站公司信息推广怎么做天津做网站的网络公司