标签:str excel xlsx type sheet files install 英文名 bsp
1 首先使用npm下载插件依赖的安装包
1 exportList() {
// json 示例
let json = [{"姓名": "***", "工號": "***", "英文名": "***", "部门": "**", "性别": "1", "手机": "+861**********",
"个人邮箱": "****@**.com"
}];
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 }
标签:str excel xlsx type sheet files install 英文名 bsp
原文地址:https://www.cnblogs.com/zxbky/p/10365886.html