Export large html table to excel using javascript - Stack Overflow

I am using following code to generate excel file from html table, It is working fine for small scale da

I am using following code to generate excel file from html table, It is working fine for small scale data set, When it es to large html table data set it is showing download error.

   //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();  

I am using following code to generate excel file from html table, It is working fine for small scale data set, When it es to large html table data set it is showing download error.

   //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();  
Share Improve this question edited Oct 14, 2017 at 19:49 glennsl 29.2k12 gold badges59 silver badges79 bronze badges asked Dec 26, 2016 at 4:30 DimuthuDimuthu 1,6811 gold badge14 silver badges16 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 2

I found one way to solve this issue using FileSaver.js 1: https://github./eligrey/FileSaver.js/ Please check followings

HTML

Javascript

this is working fine for me with large data set of HTML table.

Parsing large HTML tables can be extremely slow because of a lot of DOM elements. Please consider using a pure HTML5 canvas based data grid like this one (https://github./openfin/fin-hypergrid) or something along the line.

Also consider if saving as CSV is going to be quicker than saving as xls.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745264083a4619345.html

相关推荐

  • Export large html table to excel using javascript - Stack Overflow

    I am using following code to generate excel file from html table, It is working fine for small scale da

    13小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信