public exportAsExcelFile(json: any[], excelFileName: string): void {
const worksheet: XLSX.WorkSheet = XLSX.utils.json_to_sheet(json);
const workbook: XLSX.WorkBook = {Sheets: {'data': worksheet}, SheetNames: ['data']};
XLSX.writeFile(workbook, ExcelService.toExportFileName(excelFileName));
}
exportToExcel() {
this.accountCreationService.getExcelDataForExport().subscribe((response)=>{
if(response!=null && response.CaseList!=null && response.CaseList.length>0)
this.excelService.exportAsExcelFile(response.CaseList, 'TestData');
else
console.log('ERROR Fetching Excel Data From API')
},(error)=>{
console.log('ERROR : unable to export to EXCEL : ' + error);
})
}
My requirement was to export the data I'm getting from an API to an excel sheet.
Response Payload:
{
"pyStatusWork": "New",
"LegalCompanyName": "",
"EnablePend": null,
"DisplayId": "",
"IsLocked": false,
"taxExemptJurisdictionValue": "",
"pzInsKey": "",
"Origination": {
"BatchID": ""
},
"Source": "",
"AccountMaintenance": {
"AccountStatus": {
"RequestorType": "",
"RequestSource": "",
"CodeStatus": ""
},
"TaskType": "",
"modifiedByUserId": ""
}
}
Like this I'm getting 100's of records, the first issue is, If I export the same payload as it is to the excel sheet I'm not able to see the data under accountmaintenacne {}
and Origination {}
objects in the spreadsheet.
Second issue, I want to see different key ("key":"value") names in the spreadsheet.