likes
comments
collection
share

angular实现前端导出Excel表格

作者站长头像
站长
· 阅读数 29

<button (click)="exportExcel()"> 导出</button>// 导出exportExcel(){

if(this.data === undefined) {
  this.data = []
  this.data.push(['ID','名称','地址','流水线起始端','流水线起始端'])
}
console.log(this.data)
this.utilsService.$http.post<GetDevicesResponse>(this.utilsService.$server + '/api/devices',{
    "entriesPerPage": 20,
    "pageNumber": 0
  }
).subscribe((datas) => {
  datas.devicesList.forEach(item=>{
    let array=[];
    array.push(item._id)
    array.push(item.alias)
    array.push(item.ipAddr)
    array.push(item.first)
    array.push(item.last)
    this.data.push(array)
  })
  /* generate worksheet */
  const ws: XLSX.WorkSheet = XLSX.utils.aoa_to_sheet(this.data);
  /* generate workbook and add the worksheet */
  const wb: XLSX.WorkBook = XLSX.utils.book_new();
  XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');
  // /* save to file */
  XLSX.writeFile(wb, 'Sheet2.xlsx');

});

}