---- AI试用 ---域名问题某些图片和js资源无法访问,导致一些代码实例无法运行!(代码里gzui.net换成momen.vip即可)

导出Excel

前端开发 蚂蚁 1228℃ 0评论
//import { parseTime } from "@/utils/index";
import { Message } from 'element-ui';

/**
 * 导出Excel
 * @param {*} data 导出Excel文件流数据
 * @param {*} fileName 导出Excel文件名称
 */
export function exportExcel(data, fileName) {
  const contentByExportExcel = data;
  const blobByExportExcel = new Blob([contentByExportExcel], { type: "application/vnd.ms-excel;charset=utf-8" });
  console.log('blobByExportExcel',blobByExportExcel);
  // const filenameByExportExcel = fileName + "_" + parseTime(new Date(), "{y}-{m}-{d}") + "_" + new Date().getTime() + ".xlsx";
  const filenameByExportExcel = fileName + Date.parse(new Date()) + ".xlsx";
  if ('download' in document.createElement('a')) {
    const elink = document.createElement('a');
    elink.download = filenameByExportExcel;
    elink.style.display = 'none';
    elink.href = URL.createObjectURL(blobByExportExcel);
    document.body.appendChild(elink);
    elink.click();
    URL.revokeObjectURL(elink.href);
    document.body.removeChild(elink);
    Message({
      message: "导出Excel成功!",
      type: 'success',
      showClose: true,
      center: true
    });
  } else {
    navigator.msSaveBlob(blobByExportExcel, filenameByExportExcel);
    Message({
      message: "导出Excel成功!",
      type: 'success',
      showClose: true,
      center: true
    });
  }
}

转载请注明:有爱前端 » 导出Excel

喜欢 (0)or分享 (0)