How to Save .Xlsx Data to File as a Blob

Download an excel(.xlsx) file using blob in angular 2

You could probably just use fetch and file-saver to retrieve the Excel file:

import { saveAs } from 'file-saver';

// Client side.
// Note: it helps it server serves the appropriate response header, like e.g.
// 'Content-Type': 'application/vnd.openxmlformats'

return fetch(excelFileUrl, { headers: headerInfo })
.then(res => res.blob()) // extract binary blob from response
.then(blob => {
// Download blob with file-saver
FileSaver.saveAs(blob, "MyFile.xlsx");
})
.catch((err) => { console.error('Excel download failed', err); });

Download XLSX via Axios from Express.js server does not work

try adding responseType:'blob' to request config option:

axios.post('/export', {
entity,
fileformat,
locale: props.locale
}, {
responseType: 'blob'
})
.then((res) => {
provideBlobDownload(filename, res.data);
});


Related Topics



Leave a reply



Submit