案例
javascript
// https://unpkg.com/xlsx@0.18.5/dist/xlsx.full.min.js
function exportXlsx(jsonData, fileName = '', mine = null) {
const workbook = XLSX.utils.book_new();
// 将JSON数组转换成工作表
const worksheet = XLSX.utils.json_to_sheet(jsonData);
// 向工作簿添加工作表
XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1');
fileName = !fileName? 'output': fileName
mine = typeof mine != 'string'? 'xlsx': mine
XLSX.writeFile(workbook, [fileName, mine].join('.'));
}
exportXlsx([{name: '张三', age: 13, sex: '男'}, {name: '李四', age: 14, sex: '女'}])