ahmed elbarbary

ahmed elbarbary

  • NA
  • 1.6k
  • 256.5k

Export to excel not working when export any json data object

May 9 2020 12:27 PM
I work on angular 7 app i export data to excel it generate file excel but cannot open it
 
why and how to solve issue
 
my code used as below 
  1. public exportAsExcelFile(json: any[], excelFileName: string): void {  
  2.     const worksheet: XLSX.WorkSheet = XLSX.utils.json_to_sheet(json);  
  3.     const workbook: XLSX.WorkBook = { Sheets: { 'data': worksheet }, SheetNames: ['data'] };  
  4.     const excelBuffer: any = XLSX.write(workbook, { bookType: 'xlsx', type: 'buffer' });  
  5.     this.saveAsExcelFile(excelBuffer, excelFileName);  
  6.   }  
  7.   private saveAsExcelFile(buffer: any, fileName: string): void {  
  8.     const data: Blob = new Blob([buffer], {  
  9.       type: EXCEL_TYPE  
  10.     });  
  11.     const today = new Date();  
  12.     const date = today.getFullYear() + '' + (today.getMonth() + 1) + '' + today.getDate() + '_';  
  13.     const time = today.getHours() + "-" + today.getMinutes() + "-" + today.getSeconds();  
  14.     const name = fileName + date + time;  
  15.     FileSaver.saveAs(data, name + EXCEL_EXTENSION);  
  16.   }  
  17.  getDataByRevision(RevId : any)  
  18.   {  
  19.    
  20.    console.log(this.reportdetailslist);  
  21.    this.exportAsExcelFile(this.reportdetailslist,'datarevision');  
  22.   }  
it download and generate file excel but it is not open
 
I think problem on excel it self so i open new angular app and export to excel
 
it is ok exporting without any issue
 
this meaning i have some issue on my code above
 
can you help me please  
 
Excel generating attached with post or thread