/** * ATTENTION: too many "any" type! */ export default function(rows: any, columns: any, fileName: string = 'export') { /** * XLSX bundle size is huge (more than 1MB). * This is a good solution for load via network when needed. */ import('xlsx').then((XLSX: any) => { const data: any = [[]]; columns.forEach((col: any) => { data[0].push(col.headerName); }); rows.forEach((row: any) => { const toInsert: any[] = []; columns.forEach((col: any) => { toInsert.push(row[col.field]); }); data.push(toInsert); }); const filename = `${fileName}.xlsx`; const wsName = 'Excel export data'; const wb = XLSX.utils.book_new(); const ws = XLSX.utils.aoa_to_sheet(data); XLSX.utils.book_append_sheet(wb, ws, wsName); XLSX.writeFile(wb, filename); }); }