1/**2 * JSON数据导出excel3 * @param { name, header, headerKeys, data } 参数集合4 */5export function exportJsonToExcel({ data, filename, header, headerKeys }) {6 filename = filename || `tr-export-${new Date().getTime()}`7 const resultData = formatJson(headerKeys, data)8 9 export_json_to_excel({10 header,4 collapsed lines11 data: resultData,12 filename13 })14}
调用
1const data = [{name: 'Bob', age: 18}, {name: 'Joe', age: 18}]2const header = ['姓名', '年龄']3const headerKeys = ['name', 'age']4 5exportJsonToExcel({ data, header, headerKeys })
1export function json2excelMuti(tableJson, filenames) {2 const tHeader = []3 const dataArr = []4 const sheetnames = []5 const multiHeader = []6 const merges = []7 8 for (const i in tableJson) {9 tHeader.push(tableJson[i].tHeader)10 dataArr.push(formatJson(tableJson[i].filterVal, tableJson[i].tableDatas))14 collapsed lines11 sheetnames.push(tableJson[i].sheetName)12 multiHeader.push(tableJson[i].multiHeader || [])13 merges.push(tableJson[i].merges || [])14 }15 16 export_json_to_excel({17 multiHeader,18 merges,19 header: tHeader,20 data: dataArr,21 sheetname: sheetnames,22 filename: filenames23 })24}
1const data = [2 { data: [{name: 'Bob', age: 18}, {name: 'Joe', age: 18}], tHeader: ['姓名', '年龄'], filterVal: ['name', 'age'], sheetName: 'sheet1' },3 { data: [{name: 'Bob', age: 18}, {name: 'Joe', age: 18}], tHeader: ['姓名', '年龄'], filterVal: ['name', 'age'], sheetName: 'sheet2' }4]5 6json2excelMuti(data, '导出文件名')