前端导出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' })}/>
相关推荐
IT枫斗者28 分钟前
IntelliJ IDEA 2025.3史诗级更新:统一发行版+Spring Boot 4支持,这更新太香了!
java·开发语言·前端·javascript·spring boot·后端·intellij-idea
N***p36535 分钟前
Spring Boot项目接收前端参数的11种方式
前端·spring boot·后端
NGC_66111 小时前
二分查找算法
java·javascript·算法
享誉霸王2 小时前
15、告别混乱!Vue3复杂项目的规范搭建与基础库封装实战
前端·javascript·vue.js·前端框架·json·firefox·html5
a1117762 小时前
飞机躲避炸弹 网页游戏
前端·开源·html·threejs
夏乌_Wx2 小时前
mybash:简易 Shell 实现的设计思路与核心模块解析
linux·服务器·前端
滕青山3 小时前
URL编码/解码 核心JS实现
前端·javascript·vue.js
有马贵将3 小时前
【3】前端手撕-深浅拷贝
javascript
菜鸟小芯4 小时前
【GLM-5 陪练式前端新手入门】第五篇:响应式适配 —— 让个人主页 “见机行事”
前端·人工智能
无名之逆5 小时前
你可能不需要WebSocket-服务器发送事件的简单力量
java·开发语言·前端·后端·计算机·rust·编程