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