2016-12-26 94 views
2

我使用以下代碼從html表格生成excel文件,它對於小型數據集工作正常,當涉及到大型html表格數據集時,它顯示下載錯誤。使用javascript導出大型html表格以達到excel使用javascript

//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

由於大量的DOM元素,解析大的HTML表格會非常緩慢。請考慮使用像這樣的純粹基於HTML5 canvas的數據網格(https://github.com/openfin/fin-hypergrid)或其他東西。

另外考慮如果保存爲CSV會比保存爲xls更快。