// excel.ts
import * as xlsx from 'xlsx'
export function exportXlsxFile<T>(header: T, data: Array<T>, filename: string) {
const json: Array<any> = []
data.forEach(i => {
const obj: any = {}
for (let k in i) {
if (header[k]) {
obj[header[k]] = i[k]
}
}
json.push(obj)
})
const sheet1 = xlsx.utils.json_to_sheet(json);
const wb = xlsx.utils.book_new();
xlsx.utils.book_append_sheet(wb, sheet1, 'sheet1');
xlsx.writeFile(wb, `${filename}.xlsx`);
}
留言