导出文件流
封装方法
function exportExcel(res) {
const url = window.URL.createObjectURL(res)
window.open(url, '_self')
window.URL.revokeObjectURL(url)
}
导出json
注册组件
import JsonExcel from 'vue-json-excel'
Vue.component('download-excel', JsonExcel);
使用组件
<d2-download-excel
:data="checkList"
name="订单.xls"
>
<button>导出</button>
</d2-download-excel>
导出table
import FileSaver from "file-saver";
import * as XLSX from "xlsx";
const el = document.querySelector('#table');
const ws = XLSX.utils.table_to_book(el);
const wbout = XLSX.write(ws, {
bookType: "xlsx",
bookSST: true,
type: "array",
});
const blob = new Blob([wbout], { type: "application/octet-stream" });
const name = "excel.xlsx";
FileSaver.saveAs(blob, name);
标签:xlsx,const,excel,前端,导出,window,table
From: https://www.cnblogs.com/kanyu/p/16666717.html