前端导出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' })}/>
相关推荐
kyriewen11 分钟前
奥特曼借GPT-5.5干杯,而你的Copilot正按Token收钱
前端·github·openai
AC赳赳老秦15 分钟前
投标合规提效:用 OpenClaw 实现标书 / 合同自动审核、关键词校验、格式优化,降低废标风险
开发语言·前端·python·eclipse·emacs·deepseek·openclaw
kyriewen22 分钟前
代码写成一锅粥?3个设计模式让你的项目“起死回生”
前端·javascript·设计模式
不会敲代码139 分钟前
从零搭建 AI 日记助手:用 Milvus 向量数据库实现语义搜索
javascript·openai
千寻girling1 小时前
《 Git 详细教程 》
前端·后端·面试
threelab2 小时前
Three.js UV 图像变换效果 | 三维可视化 / AI 提示词
javascript·人工智能·uv
之歆2 小时前
DAY08_CSS浮动与行内块布局实战指南(下)
前端·css
yqcoder2 小时前
CSS Position 全解析:5 种定位模式详解
前端·css
Rhi6373 小时前
从零搭建项目:React 19 + Vite 8 + Tailwind CSS v4 实战配置
前端
竹林8183 小时前
用Viem替代ethers.js:从一次签名失败到完整迁移的实战记录
前端·javascript