[英]How to export HTML table to excel using angularjs/ javascript
我已经写了下面的代码来下载文件。 它正在为有限的记录工作。 现在我的记录数超过12000。然后它挂起了浏览器,文件未下载
var ua = window.navigator.userAgent;
var msie = ua.indexOf("MSIE ");
var edgetype = ua.indexOf("Edge");
var blobObject;
if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) {
expExcelIframe.document.open("txt/html", "replace");
expExcelIframe.document.write(html);
expExcelIframe.document.close();
expExcelIframe.focus();
expExcelIframe.document.execCommand("SaveAs", true, fileName);
}
else if (edgetype > 0) {
blobObject = new Blob([html]);
window.navigator.msSaveOrOpenBlob(blobObject, fileName);
}
else {
window.open('data:application/vnd.ms-excel,' + encodeURIComponent(html));
}
替换encodeURIComponent
:
慢
window.open('data:application/vnd.ms-excel,' + encodeURIComponent(html));
var blob = new Blob([html],{type: 'data:application/vnd.ms-excel' });
var u = URL.createObjectURL(blob);
window.open(u);
这避免了转换为base64所需的占用大量内存和计算资源的步骤。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.