Skip to content

Instantly share code, notes, and snippets.

@dalmo3
Created June 17, 2021 10:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dalmo3/d26f7ae98c8de676bce064554f0be05f to your computer and use it in GitHub Desktop.
Save dalmo3/d26f7ae98c8de676bce064554f0be05f to your computer and use it in GitHub Desktop.
Download exceljs workbook from the browser
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;
});
};
@dalmo3
Copy link
Author

dalmo3 commented Jun 17, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment