xb18
xb18
文章78
标签0
分类0
excel

excel

导出excel

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 = '导出的表格';
// 生成worksheet
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',
});
本文作者:xb18
本文链接:https://moelj.com/2023/01/12/excel/
版权声明:本文采用 CC BY-NC-SA 3.0 CN 协议进行许可