Created
June 17, 2021 10:36
-
-
Save dalmo3/d26f7ae98c8de676bce064554f0be05f to your computer and use it in GitHub Desktop.
Download exceljs workbook from the browser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From user2402616 @ https://stackoverflow.com/a/58969491/10561330