前端导出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' })}/>
相关推荐
dssxyz1 分钟前
uniapp打包微信小程序主包过大问题_uniapp 微信小程序时主包太大和vendor.js过大
javascript·微信小程序·uni-app
天天扭码31 分钟前
《很全面的前端面试题》——HTML篇
前端·面试·html
xw533 分钟前
我犯了错,我于是为我的uni-app项目引入环境标志
前端·uni-app
!win !35 分钟前
被老板怼后,我为uni-app项目引入环境标志
前端·小程序·uni-app
Burt37 分钟前
tsdown vs tsup, 豆包回答一坨屎,还是google AI厉害
前端
群联云防护小杜1 小时前
构建分布式高防架构实现业务零中断
前端·网络·分布式·tcp/ip·安全·游戏·架构
ohMyGod_1233 小时前
React16,17,18,19新特性更新对比
前端·javascript·react.js
前端小趴菜053 小时前
React-forwardRef-useImperativeHandle
前端·vue.js·react.js
@大迁世界3 小时前
第1章 React组件开发基础
前端·javascript·react.js·前端框架·ecmascript
Hilaku3 小时前
从一个实战项目,看懂 `new DataTransfer()` 的三大妙用
前端·javascript·jquery