1.第一步下载包 npm install js-export-excel
2.第二步在需要的组件中导出文件 import ExportJsonExcel from 'js-export-excel'
3.应用
var option = {}; // 创建一个对象
option.fileName = "excel"; // 导出表格的名字
option.datas = [
{
sheetData: [
{ one: "一行一列", two: "一行二列" }, // 单元格内容
{ one: "二行一列", two: "二行二列" },
],
sheetName: "sheet", // sheetName sheet 名字(可有可无)(默认 sheet1)
sheetFilter: ["two", "one"], // sheetFilter 列过滤(只有在 data 为 object 下起作用)(可有可无)
sheetHeader: ["第一列", "第二列"], // 第一行的内容(可有可无)
columnWidths: [20, 20], // 每列占的宽度
}
];
// 有多条数据时,可循环数据往表格中添加数据
option.datas[0].sheetData.push(
{ one: "三行一列", two: "三行二列" },
)
var toExcel = new ExportJsonExcel(option); //new
toExcel.saveExcel(); //保存