【问题标题】:Export large html table to excel using javascript使用javascript将大型html表导出到excel
【发布时间】:2017-05-10 15:14:53
【问题描述】:

我正在使用以下代码从 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();  

【问题讨论】:

    标签: javascript html excel file-conversion


    【解决方案1】:

    我找到了一种使用FileSaver.js 解决此问题的方法 1:https://github.com/eligrey/FileSaver.js/请查看以下内容

    HTML

    Javascript

    这对我来说适用于大型 HTML 表格数据集。

    【讨论】:

      【解决方案2】:

      由于 DOM 元素很多,解析大型 HTML 表格可能会非常缓慢。请考虑使用基于纯 HTML5 画布的数据网格,例如 (https://github.com/openfin/fin-hypergrid) 或类似的东西。

      还要考虑保存为 CSV 是否会比保存为 xls 更快。

      【讨论】:

        猜你喜欢
        • 2016-05-15
        • 2013-03-11
        • 2014-06-20
        • 1970-01-01
        • 2013-06-13
        • 2011-09-27
        • 2023-03-27
        • 2012-03-10
        • 2019-10-21
        相关资源
        最近更新 更多