I'm trying to export an HTML table to Excel using this easy function that I found on the internet:
$("#btnExport").click(function(e) {
window.open('data:application/vnd.ms-excel,' + $('#tabla_datos').html());
e.preventDefault();
});
It works pretty well, but when I add an attribute to any elements in my table, like rowspan or colspan, the Excel does not export correctly.
Here's the HTML:
<div id="tabla_datos">
<table>
<tr>
<th>Columna 1</th>
<th>Columna 2</th>
<th>Columna 3</th>
</tr>
<tr>
<td colspan='2'>Dato 1</td>
<td>Dato2</td>
</tr>
<tr>
<td>Dato 3</td>
<td>dato 4</td>
<td>Dato5</td>
</tr>
</table>
</div>
<input type="button" id="btnExport" value=" Export Table data into Excel " />
And here's the jsfiddle: http://jsfiddle.net/WAR2v/