'Export to Excel on Angular 5

exportAsExcelFile(json: any[], excelFileName: string): void {
  const worksheet: XLSX.WorkSheet = XLSX.utils.table_to_sheet(json);
  const workbook: XLSX.WorkBook = {
    Sheets: {
      'data': worksheet
    },
    SheetNames: ['data']
  };
  XLSX.writeFile(workbook, `${excelFileName}_${new Date().toLocaleDateString()}.xlsx`);
}

I didn't download to file.I didn't encounter this problem on PC, I only have any problem with Tablet.



Solution 1:[1]

This may help you

You need to created ExcelService

https://stackblitz.com/edit/angular6-export-xlsx

Solution 2:[2]

If you have an array you can use json_to_sheet():

import {writeFileXLSX, utils} from 'xlsx';

///...

exportToExcel(): void {
    const data = this.data$.getValue();
    const excelBook = utils.book_new();
    const excelSheet = utils.json_to_sheet(data);
    utils.book_append_sheet(excelBook, excelSheet, 'sheet_name');
    writeFileXLSX(excelBook, "table.xlsx");
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ketan Akbari
Solution 2 ahuemmer