I am trying to export an HTML existing table to MS Excel with assigned Name. As you know exporting HTML Table to Excel file can be achieved by jQuery BUT as I said I have to add a Name to File as well.
HTML
<button id="myButtonControlID">Export Table to Excel</button>
<div id="divTableDataHolder">
<title>Demo for huge data</title>
<table>
<tbody>
<tr>
<td>abc</td>
<td>12</td>
</tr>
<tr>
<td>abc</td>
<td>12</td>
</tr>
</tbody>
</table>
</div>
So Far I have a jquery which pass data from html to PHP file as:
$( document ).ready(function() {
var naem = "MyExcel";
$("[id$=myButtonControlID]").click(function (e) {
window.open('getMyXSL.php?data=' + encodeURIComponent($('div[id$=divTableDataHolder]').html())+'&name='+name);
e.preventDefault();
});
});
and in getMyXSL.php file I have
<?php
header('Content-Disposition: attachment; filename="'.$_REQUEST['name'].'"');
header('Content-Type: application/vnd.ms-excel');
echo($_REQUEST['data']);
?>
but when I the buton clicked file generates/download a PHP file called getMyXSL.php which looks like this
<title>Demo for huge data</title>
<table>
<tbody>
<tr>
<td>abc</td>
<td>12</td>
</tr>
<tr>
<td>abc</td>
<td>12</td>
</tr>
</tbody>
</table>
Can you please let me know how to fix this and how I can export the table to .xls with a name? Thanks
