How to download the file in the XlSX format?

Good time of day. With Beck getting the contents of a file in the xlsx format, on the front you need to download it accordingly.
Provisioning code file looks like this:
const blob = new Blob([excelData], { type: mimeFromHeader });
URL.createObjectURL(blob)


After the install URL.createObjectURL(blob) in the url tag a.
The problem occurs after download. When trying to open the file in Excel I receive an error that the file is broken.
Please tell me what I'm doing wrong and how to overcome the problem

5e426ea53525b460634816.png

p.s. If receive data of the file via postman and keep igrokami, then everything works correctly.
April 7th 20 at 11:08
1 answer
April 7th 20 at 11:10
On a crowded stack sort of like the problem was solved convert Excel data file in ArrayBuffer:
var blob = new Blob([s2ab(atob(excelData))], { type: mimeFromHeader });

function s2ab(s) { // cm https://github.com/SheetJS/sheetjs/blob/master/README.md
 var buf = new ArrayBuffer(s.length);
 var view = new Uint8Array(buf);
 for (var i=0; i!=s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
 return buf;
 }
Try.

Find more questions by tags JavaScript