如何在react js中将blob数据转换为可下载的excel/CSV文件

如何在react js中将blob数据转换为可下载的excel/CSV文件,excel,reactjs,blob,Excel,Reactjs,Blob,我从Get API中得到一个blob 这里显示了响应 在得到响应后创建文件的逻辑 const url = URL.createObjectURL(new Blob([result], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' })) const link = document.createElement('a'); link.href = url; l

我从Get API中得到一个blob 这里显示了响应 在得到响应后创建文件的逻辑

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();

它正在创建损坏的excel文件。

我认为您应该尝试使用软件包。

您可以这样使用:

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

问题中附有一张照片