[英]Export large html table to excel using javascript
我正在使用以下代码从 html 表生成 excel 文件,它适用于小规模数据集,当涉及大型 html 表数据集时,它显示下载错误。
//creating a temporary HTML link element (they support setting file names)
var a = document.createElement('a');
//getting data from our div that contains the HTML table
var data_type = 'data:application/vnd.ms-excel';
var table_div = document.getElementById('dataTable');
var table_html = table_div.outerHTML.replace(/ /g, '%20');
a.href = data_type + ', ' + table_html;
//setting the file name
a.download = 'Sample.xls';
//triggering the function
a.click();
//just in case, prevent default behaviour
e.preventDefault();
我找到了一种使用FileSaver.js 1解决此问题的方法: https : //github.com/eligrey/FileSaver.js/请检查以下内容
Javascript
对于 HTML 表格的大数据集,这对我来说很好用。
由于有很多 DOM 元素,解析大型 HTML 表可能会非常慢。 请考虑使用像这样的纯 HTML5 画布数据网格( https://github.com/openfin/fin-hypergrid )或类似的东西。
还要考虑保存为 CSV 是否比保存为 xls 更快。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.