1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| import * as XLSX from 'xlsx';
const workbook = XLSX.utils.book_new(); const data = [ ['测试1', '测试2'] ]; const fileName = '导出的表格';
const worksheet = XLSX.utils.json_to_sheet(data, { skipHeader: true }); XLSX.utils.book_append_sheet(workbook, worksheet, 'sheetName'); ctx.set('Content-Type', 'application/vnd.openxmlformats'); ctx.set( 'Content-Disposition', "attachment;filename*=UTF-8' '" + encodeURIComponent(fileName) + '.xlsx', ); ctx.body = await XLSX.write(workbook, { bookType: 'xlsx', type: 'buffer', });
|