前端导出word文件,并包含导出Echarts图表等

基础导出模板

javascript 复制代码
    const html = `<html>
    <head>
      <style>
        body {
          font-family: 'Times New Roman';
        }
    
        h1 {
          text-align: center;
        }
    
        table {
          border-collapse: collapse;
          width: 100%;
          color: '#1118FF';
          font-weight: 600;
        }
    
        th,
        td {
          border: 1px solid black;
          padding: 8px;
          text-align: left;
        }
      </style>
    </head>
    
    <body>
      <div style="font-size: 20px;font-weight: 600;margin-bottom: 20px;margin-left: 15px;">
        附件:孜然卷测试问题主要问题汇总
      </div>
      <table>
        <thead>
          <tr>
            <th>科室</th>
            <th>住院号</th>
            <th>问题</th>
            <th>管床医生</th>
            <th>扣分</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <th>孜然卷科室test1</th>
            <th>住院号test1</th>
            <th>问题test1</th>
            <th>管床医生test1</th>
            <th>扣分test1</th>
          </tr>
        </tbody>
      </table>
    </body>
    
    </html>`;
    const blob = new Blob([html], {
      type: 'application/msword',
    });
    const link = document.createElement('a');
    link.download = `2025年2月导出.doc`;
    link.href = URL.createObjectURL(blob);
    link.click();

其中如果要加入Echarts图表,则需在创建Echarts图表时,将其myChartWord保存

在需要引用图片时 使用上面保存的myChartWord的getDataURL()函数
html 复制代码
<img src=${this.state.myChartWord.getDataURL({ pixelRatio: 2, backgroundColor: '#fff' })}/>
相关推荐
木斯佳2 分钟前
前端八股文面经大全:2026-02-09快手春招前端一面
前端·状态模式
兆子龙3 分钟前
深入 ahooks 3.0 useRequest 源码:插件化架构的精妙设计
javascript·面试
闲云一鹤8 分钟前
UV 包管理器 - 新一代的 Python 包和环境管理神器
前端·python
电商API_1800790524720 分钟前
淘宝商品详情数据获取全方案分享
开发语言·前端·javascript
Amumu1213844 分钟前
CSS简介
前端·css
Yzw1 小时前
当vue.diff遇上了扩展运算符(...)
前端
前端不开发1 小时前
在任意网页里“召唤”一个火柴人:一次有趣的 JavaScript Hack
前端·javascript
whatever who cares1 小时前
Java Web 架构全组件详解
java·前端·架构
DevDengChao1 小时前
[Aliyun] [FC] 如何使用 website-fc-serve 插件部署静态网站
前端·后端
前端拿破轮1 小时前
利用Github Page + Hexo 搭建专属的个人网站(一)
前端·人工智能·后端