使用javascript将大型html表导出为ex​​cel

时间:2023-01-29 09:56:40

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

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

2 个解决方案

#1


1  

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

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

HTML 使用javascript将大型html表导出为ex​​cel

HTML

Javascript

使用Javascript

使用javascript将大型html表导出为ex​​cel

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

对于我来说,这对HTML表的大数据集很有用。

#2


0  

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.com/openfin/fin-hypergrid) or something along the line.

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

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

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

#1


1  

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

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

HTML 使用javascript将大型html表导出为ex​​cel

HTML

Javascript

使用Javascript

使用javascript将大型html表导出为ex​​cel

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

对于我来说,这对HTML表的大数据集很有用。

#2


0  

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.com/openfin/fin-hypergrid) or something along the line.

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

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

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