import { utils, writeFile } from "xlsx"; /** * 导出 excel 文件 * @param array JSON 数组 * @param sheetName 第一张表名 * @param fileName 文件名 */ export function exportExcelFile( array = [], sheetName = "sheet1", fileName = "example.xlsx" ) { const jsonWorkSheet = utils.json_to_sheet(array); const workBook = { SheetNames: [sheetName], Sheets: { [sheetName]: jsonWorkSheet, }, }; return writeFile(workBook, fileName); }