0

I'm using ExcelJS to export excel file from JSON, the export works good but I need to add some changes in the excel file likes: color - font - width and etc. And also I'm asking if I can write in an excel file already customized with a model.

Here is the service :

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'] };
  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 + '_export_' + EXCEL_EXTENSION);
}

And thats how I call it:

this.excelService.exportAsExcelFile(dealTable, 'deals');
Mort
  • 1,411
  • 5
  • 19
  • 51

1 Answers1

0

To my knowledge styling is supported in SheetJS Pro. You can also look into ExcelJS which is not a paid version, but is slightly buggy.

Adri
  • 16
  • 1