// 安装插件
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表格
5万+

被折叠的 条评论
为什么被折叠?



