import * as XLSX from 'xlsx' // vue3可用此引入
import XLXS from "xlsx"; // vue2可用此引入
let arr = [
{ id: 1, sex: "男", name: "李二" },
{ id: 2, sex: "女", name: "李兰" },
];
let aoa = [["名称", "id", "sex"]];
for (let i = 0; i < arr.length; i++) {
let ava = arr[i];
aoa.push([ava.name, ava.id, ava.sex]);
}
//处理成表格的位置信息
const sheet = XLSX.utils.aoa_to_sheet(aoa);
const wb = {
SheetNames: ["sheet1"],
Sheets: {
sheet1: sheet,
},
};
XLSX.writeFile(wb, "航空关联列表.xlsx", {
bookType: "xlsx",
bookSST: false,
type: "file",
});