导出大的HTML表格,以使用JavaScript的Excel

我正在使用下面的代码从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/请检查以下

HTML 在这里输入图像说明

使用Javascript

在这里输入图像说明

这对我的HTML表格的大数据集合工作正常。

由于大量的DOM元素,parsing大的HTML表格会非常缓慢。 请考虑使用一个纯HTML5基于canvas的数据网格,就像这个( https://github.com/openfin/fin-hypergrid )或者沿线的东西。

另外考虑保存为CSV会比保存为xls更快。