【发布时间】: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