I have successfully implemented functions to export JSON data to Excel using the code below:
public exportAsExcelFile(json: any[], excelFileName: string) :Promise<Object> {
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' });
return (this.saveAsExcelFile(excelBuffer, excelFileName));
}
private saveAsExcelFile(buffer: any, fileName: string):Promise<Object> {
const data: Blob = new Blob([buffer], {type: EXCEL_TYPE});
return await FileSaver.saveAs(data, fileName + '-' + new Date().toString()+ EXCEL_EXTENSION);
}
However, I am struggling with formatting the exported Excel file. Specifically, I want to include bold headers and ensure that the cells autofit.