Skip to content

Instantly share code, notes, and snippets.

@dalmo3
Created June 17, 2021 10:36

Revisions

  1. dalmo3 created this gist Jun 17, 2021.
    19 changes: 19 additions & 0 deletions downloadSheet.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    export const downloadSheet = (workbook: ExcelJS.Workbook) => {
    workbook.xlsx
    .writeBuffer()
    .then((buffer) => {
    // buffer --> blob
    const blob = new Blob([buffer], { type: 'application/vnd.ms-excel' });

    const link = document.createElement('a');
    link.download = 'download.xlsx';
    link.target = 'blank';

    // blob --> url
    link.href = URL.createObjectURL(blob);
    link.click();
    })
    .catch((err) => {
    throw err;
    });
    };