Last post May 11, 2020 07:32 AM by Rena Ni
Member
39 Points
362 Posts
May 09, 2020 10:48 PM|ahmedbarbary|LINK
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)
Contributor
2690 Points
874 Posts
May 11, 2020 07:32 AM|Rena Ni|LINK
Hi ahmedbarbary,
For how to download the Excel file,you could refer to:
https://stackoverflow.com/questions/54889629/angular-7-unable-to-download-file-with-c-sharp-net-core-api
Best Regards,
Rena
Member
39 Points
362 Posts
when export data to excel error excel file not readable content?
May 09, 2020 10:48 PM|ahmedbarbary|LINK
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
Angular service.ts
component.ts
component .html
Data below is result of API and angular above and this data Exactly must show on Excel But this Not Done
Contributor
2690 Points
874 Posts
Re: when export data to excel error excel file not readable content?
May 11, 2020 07:32 AM|Rena Ni|LINK
Hi ahmedbarbary,
For how to download the Excel file,you could refer to:
https://stackoverflow.com/questions/54889629/angular-7-unable-to-download-file-with-c-sharp-net-core-api
Best Regards,
Rena