angular实现前端导出Excel表格


// 导出
exportExcel(){

if(this.data === undefined) {
  this.data = []
  this.data.push(['ID','名称','地址','流水线起始端','流水线起始端'])
}
console.log(this.data)
this.utilsService.$http.post(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');

});

}

你可能感兴趣的:(angular实现前端导出Excel表格)