js导出后台当前页面查询的表格数据

使用插件js-export-excel将table数据导出为excel文件

首先在项目中安装js-export-excel插件,进入项目目录,执行以下命令:
npm安装:npm install --save js-export-excel,

const downloadExcel = () => {
    const getRepaymentPlanList = exceldata ? exceldata : '';//exceldata 表格总数据
    let option = {};  //option代表的就是excel文件
    let dataTable = [];  //excel文件中的数据内容
    if (getRepaymentPlanList && getRepaymentPlanList.length > 0) {
      for (let i in getRepaymentPlanList) {  //循环获取excel中每一行的数据
        // let _planDay = formatTime(getRepaymentPlanList[i].createdAt, true);  //格式化日期(自定义方法)
        let obj = {
          'ID': getRepaymentPlanList[i].id,
          '会员id': getRepaymentPlanList[i].memberid,
          '账变id': getRepaymentPlanList[i].account_changeid,
          '出金方式': getRepaymentPlanList[i].way,
          '汇率': getRepaymentPlanList[i].parities,
          '原币金额': getRepaymentPlanList[i].price,
          '本位币金额(美金)': getRepaymentPlanList[i].money,
          '备注': getRepaymentPlanList[i].remark,
          '创建人': getRepaymentPlanList[i].author,
          '创建时间': getRepaymentPlanList[i].creation_time,
          '状态': getRepaymentPlanList[i].status,
          // '事件':_planDay
        }
        dataTable.push(obj);  //设置excel中每列所获取的数据源
      }
    }
    option.fileName = '出金查询数据';  //excel文件名称
    option.datas = [
      {
        sheetData: dataTable,  //excel文件中的数据源
        sheetName: '出金查询数据',  //excel文件中sheet页名称
        sheetFilter: ['ID','会员id','账变id','出金方式','汇率','原币金额','本位币金额(美金)','备注','创建人','创建时间','状态'],  //excel文件中需显示的列数据
        sheetHeader: ['ID','会员id','账变id','出金方式','汇率','原币金额','本位币金额(美金)','备注','创建人','创建时间','状态'],  //excel文件中每列的表头名称
      }
    ]
    let toExcel = new ExportJsonExcel(option);  //生成excel文件
    toExcel.saveExcel();  //下载excel文件
  }
调用 downloadExcel 方法

在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值