Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { data } = await axios.get('/api/admin/export-user', {
- headers: {
- 'Authorization': 'Bearer' + localStorage.getItem('token')
- },
- responseType: 'blob'
- });
- let blob = new Blob([data], { type: "application/vnd.ms-excel" }),
- fileName = 'users.xls';
- if (window.navigator && window.navigator.msSaveOrOpenBlob) { // for IE
- window.navigator.msSaveOrOpenBlob(blob, fileName);
- } else { // for Non-IE (chrome, firefox etc.)
- let a = document.createElement("a"),
- url = window.URL.createObjectURL(blob);
- document.body.appendChild(a);
- a.setAttribute('id', 'download-file');
- a.setAttribute('style', 'display: none');
- a.setAttribute('href', 'data:attachment/xlsx,' + url);
- a.setAttribute('download', fileName);
- a.click();
- window.URL.revokeObjectURL(url);
- document.querySelector('#download-file').remove();
- }
Add Comment
Please, Sign In to add comment