Vue导出excel表格

// 安装插件
npm install js-table2excel

//导入插件
import table2excel from 'js-table2excel'

js-table2excel是通过数据进行打印的所有需要先获取要打印的数据

// 这边是一个数据格式模板,具体数据可以通过查询数据库获得
 tableData: [{
        user_name: null,
        user_school: null,
        user_grade: null,
        user_jobs: null,
        user_type: null
      }],

点击导出的时候调用exportExcel方法

exportExcel() {
        // 1.title为列名
        // 2.key为data数据每个对象对应的key
        // 3.若为图片格式, 需要加type为image的说明,并且可以设置图片的宽高
      const column = [
        {
          title: '姓名',
          key: 'user_name',
          type: 'text'
        },
        {
          title: '年级',
          key: 'user_grade',
          type: 'text'
        },
        {
          title: '学校',
          key: 'user_school',
          type: 'text'
        },
        {
          title: '期望职位',
          key: 'user_jobs',
          type: 'text',
          width: 80,
          height: 50
        },
        {
          title: '求职者类型',
          key: 'user_type',
          type: 'text',
        },
      ]


      const data = this.allData
      const excelName = `模拟面试报名数据`
      table2excel(column, data, excelName)
    },
    // 方法执行时页面会让选择一个路径用于保存excel表格
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值