0%
使用XLSX
1 2 3 4 5 6
| export async function export(params) { return request('/api/export', { params, responseType:"arrayBuffer" }); }
|
1 2 3 4 5
| const blob = await service.export(processParams(params)); const data = new Uint8Array(v); const workbook = XLSX.read(data, { type: "array" }); const wopts = { bookType: 'xlsx', bookSST: false, type: 'array' }; XLSX.writeFile(workbook, 'a.xlsx');
|
优点是跨平台 React Native也可以
缺点是导出的excel文件样式丢失
blob方式
1 2 3 4 5 6
| export async function exportOperateLogs(params?: any) { return request('/api/blob/export', { params, responseType:"blob" }); }
|
1 2 3 4 5 6 7 8 9 10 11 12
| if (window.navigator.msSaveOrOpenBlob) { navigator.msSaveBlob(blob, 'excel.xlsx'); } else { var link = document.createElement('a'); link.href = window.URL.createObjectURL(blob); link.download = "a.xlsx"; document.body.appendChild(link); var evt = document.createEvent("MouseEvents"); evt.initEvent("click", false, false); link.dispatchEvent(evt); document.body.removeChild(link); }
|
优点:原样导出
缺点:只适用于浏览器