I have a html table
that adds the row data dynamically
by taking user input. How can I export this table data to 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>
i am able to add the rows but unable to download the excel file. Any help would be appriciated