2

i am getting a blob from the Get API click here to see the format with response shown here response logic to create file like so after getting the response.

const url = URL.createObjectURL(new Blob([result], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }))
      const link = document.createElement('a');
      link.href = url;
      link.innerText = 'Open the array URL';
      link.setAttribute('download', 'myExcel.xlsx');
      link.click();

its creating corrupted excel file.

Rajat
  • 111
  • 4
  • 14

3 Answers3

1

create headers like this

const headers = {Accept: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",};

and the your request in axios

Axios.get("my-api/stream", { responseType: 'blob',headers });
Harsh Mangalam
  • 1,116
  • 1
  • 10
  • 19
0

I think you should try to use FileSaver package.

Kirill Skomarovskiy
  • 1,535
  • 1
  • 7
  • 9
0

You can use like this:

saveAs(new Blob([result], {type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'}), 'myExcel.xlsx');