locked
when export data to excel error excel file not readable content? RRS feed

  • Question

  • User696604810 posted

    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 .

    Exec exec dbo.getRevision 19253747
    Main issue why not export data to excel and how to make export correct this actually what i need .

    web API asp.net core 2.2

    [HttpPost]
    
    public IActionResult GetDataBasedOnDynamicSp([FromBody] dynamic DataObjectRevision)
    {
    
    string SpName = DataObjectRevision[0].downLoadProcedureName;
    
    string revid = DataObjectRevision[0].revisionID;
    var PostRevision = _reportservice.GetSpByRevisionId(revid, SpName);
    
    return Ok(PostRevision);
    
    
    
    }



    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)



    Saturday, May 9, 2020 10:48 PM

All replies