when export data to excel error excel file not readable content?




Asked on May 09, 2020

problem

 

I work on angular 7 app I click button to export data from database to Excel it create file when i open it

 

give me error ( excel file not readable content ) why and how to solve issue this my problem .

 

I pass parameter value to stored procedure and execute it and get result from database then export it to excel .

 

Main issue why not export data to excel and how to make export correct this actually what i need .

 

 

Angular service.ts

GetSpByRevisionId(datarevision : any){

    return this.http.post<any>('http://localhost:61265/api/report',datarevision)

 

  }

component.ts

public exportJsonAsExcelFile(json: any[], excelFileName: string): void {

    const worksheet: XLSX.WorkSheet = XLSX.utils.json_to_sheet(json);

    const workbook: XLSX.WorkBook = { Sheets: { 'data': worksheet }, SheetNames: ['data'] };

    const excelBuffer: any = XLSX.write(workbook, { bookType: 'xlsx', type: 'array' });

    this.saveAsExcelFile(excelBuffer, excelFileName);

  }

  private saveAsExcelFile(buffer: any, fileName: string): void {

    const data: Blob = new Blob([buffer], { type: EXCEL_TYPE });

    FileSaver.saveAs(data, fileName + new Date().getTime() + EXCEL_EXTENSION);

  }

 getDataByRevision(RevId : any)

  {

 

    this.ReportData.forEach(function(e) { e.revisionID=RevId });

    this._displayreport.GetSpByRevisionId(this.ReportData).subscribe(data=>{

console.log(data)

this.exportJsonAsExcelFile(this.ReportData ,'datarevision');

    });

 

 

  }

component .html

 <td> <button (click)="getDataByRevision(rep[0])">Download</button> </td>

Data below is result of API and angular above and this data Exactly must show on Excel But this Not Done

 

(3) [{…}, {…}, {…}]

0: {revisionid: 19253747, revisionname: "parts", revisioncity: "usa"}

1: {revisionid: 19253747, revisionname: "company", revisioncity: "russia"}

2: {revisionid: 19253747, revisionname: "family", revisioncity: "german"}

length: 3

__proto__: Array(0)



Write Answer











©2024 concretepage.com | Privacy Policy | Contact Us