导出excel

  const exportToWord = (response, filename) => {
    const elink = document.createElement('a');
    elink.style.display = 'none';

    const blob = new Blob([response], {
      type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
    });

    const blobUrl = URL.createObjectURL(blob);
    elink.href = blobUrl;
    elink.download = filename; // 设置下载后的文件名

    document.body.appendChild(elink);
    elink.click();

    document.body.removeChild(elink);
    URL.revokeObjectURL(blobUrl);
  };

  const handleDownload = async () => {
    try {
      const res = await downloadElementDaily({
        archive_date: selectedDate.format('YYYY-MM-DD'),
      });
      exportToWord(res, '资产异常列表.xlsx');
    } catch (error) {
      console.error('Error downloading data:', error);
    }
  };

定义接口时,一定要加上responseType: ‘blob’

export async function downloadElementDaily(params) {
  return request('/server/v1/cost/element/daily/download', {
    method: 'GET',
    params: { ...params },
    responseType: 'blob',
  });
}

相关推荐

  1. excel导入导出

    2024-07-15 13:44:03       34 阅读
  2. 导出excel

    2024-07-15 13:44:03       21 阅读
  3. Excel 导入导出的封装

    2024-07-15 13:44:03       34 阅读
  4. hutool ExcelUtil 导出导入excel

    2024-07-15 13:44:03       25 阅读
  5. 用于Web导出excel

    2024-07-15 13:44:03       48 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-15 13:44:03       66 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-15 13:44:03       70 阅读
  3. 在Django里面运行非项目文件

    2024-07-15 13:44:03       57 阅读
  4. Python语言-面向对象

    2024-07-15 13:44:03       68 阅读

热门阅读

  1. 启动hive元数据服务

    2024-07-15 13:44:03       22 阅读
  2. 优化调试体验:让PyCharm的调试过程飞起来

    2024-07-15 13:44:03       23 阅读
  3. C 习题答案20240710-前置

    2024-07-15 13:44:03       22 阅读
  4. 使用css3实现【水波纹扩散效果】

    2024-07-15 13:44:03       24 阅读
  5. C++小白Python选手2小时入门C++

    2024-07-15 13:44:03       29 阅读
  6. 树莓派pico入坑笔记,at24c256使用

    2024-07-15 13:44:03       20 阅读
  7. Postcat使用全解析

    2024-07-15 13:44:03       24 阅读
  8. Mojo 编程语言入门:AI开发者的新宠儿

    2024-07-15 13:44:03       25 阅读
  9. 721. 账户合并

    2024-07-15 13:44:03       22 阅读
  10. ZZULIOJ1073: 再谈鸡兔同笼问题

    2024-07-15 13:44:03       21 阅读
  11. git统计工程某目录代码总行数

    2024-07-15 13:44:03       21 阅读