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

纯前端实现将页面数据下载word文档中【包括图片,echarts图,表格,和对话 内容】

亲测真实有效

导出word步骤

在Vue中导出Word文档,可以使用第三方库file-saver和html-docx-js。首先需要安装这两个库:

npm install file-saver html-docx-js --save

  "html-docx-js": "0.3.1","file-saver": "2.0.5",

然后在Vue组件中使用这两个库来导出Word文档:

vue

 <chat-operation :info="info" @down="down" ref="chatItem"/>

js

down() {const contenterPdf = this.$refs.chatItemconst canvases = contenterPdf.querySelectorAll('canvas')const cloneDom = contenterPdf.cloneNode(true)if (canvases.length) {const cloneCanvases = cloneDom.querySelectorAll('canvas')const imgs = []canvases.forEach((canvas) => {const img = document.createElement('img')const url = canvas.toDataURL()img.src = urlimg.width = canvas.width >= 750 ? 750 : canvas.widthimg.height = canvas.height >= 560 ? 560 : canvas.heightimgs.push(img)})cloneCanvases.forEach((canvas, index) => {canvas.parentNode.replaceChild(imgs[index], canvas)})}// 过滤代码块序号元素const numberDoms = cloneDom.querySelectorAll('.number-container')numberDoms.forEach(dom => {dom.remove()})const contentHTML = cloneDom.innerHTMLconst content = `<!DOCTYPE html><html lang='en'><head><meta charset='UTF-8'></head><body>${contentHTML}</body></html>`const html = htmlDocx.asBlob(content, { orientation: 'portrait', pageSize: 'A4' })FileSaver.saveAs(html, `导出文件.docx`)},
http://www.lryc.cn/news/352543.html

相关文章:

  • JavaSE——类和对象(二)~~封装
  • 头歌OpenGauss数据库-I.复杂查询第9关:交换性别
  • 冷干机使用中的注意事项
  • OpenFeign微服务调用组件使用
  • 文心智能体,零代码构建情感表达大师智能体
  • es6
  • 「贪心算法」柠檬水找零
  • ssm139选课排课系统的设计与开发+vue
  • Python使用virtualenv创建虚拟环境
  • LuatOS-Air二次开发学习
  • 【Linux】关于获取进程退出状态中的core dump标志补充
  • Vitis HLS 学习笔记--抽象并行编程模型-控制驱动与数据驱动
  • Python爬取B站视频:封装一下
  • Android Low Storage机制之DeviceStorageMonitorService
  • 1105: 交换二叉树的孩子结点
  • TensorFlow.js
  • 131. 面试中关于架构设计都需要了解哪些内容?
  • Nodejs+Websocket+uniapp完成聊天
  • 神经网络学习
  • CentOS部署NFS
  • JWT使用方法
  • 使用鱼香肉丝一键安装重新安装ROS后mavros节点报错,.so文件不匹配
  • STM32+CubeMX移植SPI协议驱动W25Q16FLash存储器
  • gpt-4o考场安排
  • 【Unity AR开发插件】四、制作热更数据-AR图片识别场景
  • Spring AOP的实操 + 原理(动态代理)
  • 16.线性回归代码实现
  • Java进阶学习笔记1——课程介绍
  • 【全开源】沃德商协会管理系统源码(FastAdmin+ThinkPHP+Uniapp)
  • python毕设项目选题汇总(全)