excel - 使用 blob url 以 Angular 7 下载 excel 文件
问题描述
我正在尝试使用 mime 类型“ data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet ”在我的 angular 7 应用程序中下载 excel 文件,但是当我尝试打开下载的文件时,它会抛出一些错误说 - http://prntscr.com/ur1nc4。
这是我为下载文件所做的
const filePath = "https://bviewstorage.blob.core.windows.net/9be306d9-acb1-4f25-a54f-5126e021ec6d/hrm/aabe5bd4-940a-4246-979c-581fdaa45808/Client_export_1592830934796-94f5d780-4007-4ae6-b802-53f4fe5509f2.xlsx"
const linkSource = "data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet," + filePath;
const downloadLink = document.createElement("a");
downloadLink.href = linkSource;
downloadLink.download = "ExcelTemplate" + this.datePipe.transform(new Date(), "yyyy-MM-dd") + ".xlsx";
downloadLink.click();
我什至尝试下载文件路径“xls”MIME 类型,但仍然抛出相同的错误。
请告诉我下载excel文件的方法。
解决方案
const filePath = "https://bviewstorage.blob.core.windows.net/9be306d9-acb1-4f25-a54f-5126e021ec6d/hrm/aabe5bd4-940a-4246-979c-581fdaa45808/Client_export_1592830934796-94f5d780-4007-4ae6-b802-53f4fe5509f2.xlsx"
if(window) {
window.open(filePath);
}
由于您的文件不安全,因此可以使用上述代码下载。window.open 打开一个新的浏览器窗口,它将直接从 blob 下载文件。
推荐阅读
- python - List index out of error when parsing html with bs4 and pandas
- r - 如何使用新变量加入数据框?
- python - Python BoxPlot 错误 - 'Series' 对象没有属性 'boxplot'
- python - Python:查找两个列表中存在的给定长度的公共子列表
- python-3.x - 广度优先搜索:使用 Python 的最短路径
- mysql - 使用java在sql中查找具有相同数据的具有相同值的行?
- kotlin - Kotlin:如何限制块内的范围?
- node.js - 如何在 Firebase 上使用已部署的应用程序和已部署的函数存储数据
- html - Bootstrap 4 nav-tabs 下拉项目不通过活动标签面板切换
- actions-on-google - 针对网站而非应用的 Google 品牌名称所有权验证操作