安装 npm install js-export-excel
import React, { Component } from 'react'
import ExportJsonExcel from 'js-export-excel';
export default class Show extends Component {
editor = () => {
const option = {};
// 文件名字
option.fileName = 'excel';
// 文件的数据集
option.datas = [
{
// 通常用来放我们的表格数据
sheetData: [
{ name: "hig girl", old: 12 },
{ name: "you boy", old: 20 },
],
// sheet名字
sheetName: 'sheet',
// 第一行
sheetHeader: ['名字', '年龄'],
//列宽 需与列顺序对应, 需要则写
// columnWidths: []
}
]
const toExcel = new ExportJsonExcel(option);
let file = toExcel.saveExcel()
}
render() {
return (
<div>
show
<button onClick={this.editor}>下载</button>
</div>
)
}
}