javascript - JavaScript 中的 Excel 导出无法使用 Blob
问题描述
我有一些javascript问题。我正在努力下载 xlsx 格式的文件。在后端工作一切正常 - 使用例如 swagger 下载文件。
我的代码:
private async downloadDocumentTemplate(report: string) {
this.fileLoading = true;
try {
const result = await this.$store.dispatch("report/downloadDocument", report);
const blob = new Blob([result], {type: "application/octet-stream"});
var reader = new FileReader();
reader.addEventListener("loadend", function() {
});
reader.readAsArrayBuffer(blob);
console.log("blob contnet : " + blob.type);
FileSaver.saveAs(blob, 'report.xlsx');
} catch (ex) {
this.$store.commit("app/showErrorPopup", ex);
}
this.fileLoading = false;
}
从网上下载文件后,文件自动打开,我遇到如下错误:
“我们发现某些内容 .xlsx 存在问题。您希望我们尽可能多地尝试恢复吗?” e
解决方案
我有一些类似的问题。我的问题是我如何解析 Excel 数据。脚本输入了错误的格式信息。
如果可以将文件下载到计算机上,则解析 excel 数据的代码中一定有错误。
推荐阅读
- jenkins - 当前使用 hudson.model.DirectoryBrowserSupport.CSP 问题覆盖了默认的 Content-Security-Policy
- python - 如何使用 beautifullsoup 从该站点抓取数据
- regex - 如何从 env 系统命令的输出中输出潜在的多行环境变量?
- reactjs - 如何将 webpack 与现有的 react 项目集成
- r - R:将每日收益转换为每月收益
- reactjs - 非常简单的 MWE,打字稿错误 TS2322 (...) 不能分配给类型 'IntrinsicAttributes & Props & { children?: ReactNode; }'
- azure - COSMOS DB 部署失败
- html - Web 文档的编码与文档中明确使用的编码之间的混淆
- sql - 数据库模式、数据库和数据之间的区别 - 版本控制
- string - BASH 拆分一个字符串并返回该单词之前的所有文本