我有一个html table
,它通过接受用户输入来添加行数据 dynamically
。如何将表格数据导出到Excel?
function fnExcelReport() {
var table = document.getElementById("myTableData");
var html = table.outerHTML;
var url = 'data:application/vnd.ms-excel,' + escape(html);
html table into url
elem.setAttribute("href", url);
elem.setAttribute("download","export.xls");
return false;
}
Name:<input type="text" id="name">
Age:<input type="text" id="age">
<input type="button" id="add" value="Add" onclick="Javascript:addRow()">
<table id="myTableData" border="1px" cellpadding="2">
<tr>
<td> </td>
<td><b>Name</b></td>
<td><b>Age</b></td>
</tr>
</table>
<a href="#" id="test" onClick="javascript:fnExcelReport();">download</a>
我能够添加行,但无法下载Excel文件。任何帮助都将得到