I have below code to call api which returns bytes for excel.
When I convert bytes to excel online , file looks good.
But , When I call api through react js with below code , it gives me error –
We found a problem with content in <file.xlsx>. Do you want to recover
as mych as we can?
agent.ExcelExport(data,{
responseType:"arraybuffer"
})
.then((res:any)=>{
const url= window.URL.createObjectURL( new Blob([res.data],{type:"application/x-msdownload"}));
const link=document.createElement('a');
link.href=url;
link.setAttribute('download','filename.xlsx');
link.click();
window.URL.revokeObjectURL(url);
I can see , Api getting hit clearly and responding with expected data. While opening file , its giving error.
.NET Core Api is returning –
return File(excelbytes,”application/x-msdownload”,”filename.xlsx”);