'How to export to excel file from API

Have angular datatable and table contains more than 50k records, if we trying to export to excel taking lot of time and browser is not responding. If possible could you pls guide me how to export to excel with large det of data without displaying table. Tried below approach, but getting issues, please suggest me.

  exportToExcel() {
    const ws: XLSX.WorkSheet = XLSX.utils.table_to_sheet(
      this.table.nativeElement
    );
    const wb: XLSX.WorkBook = XLSX.utils.book_new();
    XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');
    /* save to file */
    XLSX.writeFile(wb, 'SheetJS.xlsx');
  }

It would be very great help to get some examples and guidance.

Demo



Solution 1:[1]

If you haven't completed this by now, here's the basic process to handle creating an Excel document Server-side:

  1. Instantiate the Excel Document in memory
  2. Gather your data,
  3. Instantiate and populate a worksheet with the Excel Document as the parent
  4. Add the worksheet to the excel document
  5. Send the Excel document as a whole to the browser

Unfortunately I don't have a coded example for you in JavaScript. As a .Net dev, I don't use JS much these days

Solution 2:[2]

If making it in browser becomes slow best option is to do it in the backend.

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 Andrew McFall III
Solution 2 Tharu D