1 首先使用npm下載插件依賴的安裝包linux
1 exportList() {
// json 示例
let json = [{"姓名": "***", "工號": "***", "英文名": "***", "部門": "**", "性別": "1", "手機": "+861**********",
"我的郵箱": "****@**.com"
}];
npm
2 let json = this.linuxRow; 3 //linuxRow是要導出的json數據,能夠根據選擇來命名 4 const worksheet: XLSX.WorkSheet = XLSX.utils.json_to_sheet(json); 5 const workbook: XLSX.WorkBook = { 6 Sheets: { data: worksheet }, 7 SheetNames: ['data'] 8 }; 9 const excelBuffer: any = XLSX.write(workbook, { 10 bookType: 'xlsx', 11 type: 'array' 12 }); 13 //這裏類型若是不正確,下載出來的多是相似xml文件的東西或者是相似二進制的東西等 14 this.saveAsExcelFile(excelBuffer, 'linux安裝詳情'); 15 } 16 private saveAsExcelFile(buffer: any, fileName: string) { 17 const data: Blob = new Blob([buffer], { 18 type: 19 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8' 20 }); 21 FileSaver.saveAs(data, fileName + '_' + new Date().getTime() + '.xlsx'); 22 // 若是寫成.xls,可能不能打開下載的文件,這可能與Excel版本有關 23 }