我使用以下代码从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();
答案 0 :(得分:1)
我找到了一种使用FileSaver.js解决此问题的方法 1:https://github.com/eligrey/FileSaver.js/请检查以下内容
的Javascript
对于HTML表格的大数据集,这对我来说很好。
答案 1 :(得分:0)
由于有很多DOM元素,解析大型HTML表格可能会非常慢。请考虑使用纯HTML5基于画布的数据网格(如https://github.com/openfin/fin-hypergrid)或其他内容。
另外考虑保存为CSV会比保存为xls更快。