在表格元素上使用属性时,无法将HTML表格导出到Excel

我正在尝试使用在Internet上find的这个简单函数将HTML表格导出到Excel:

$("#btnExport").click(function(e) { window.open('data:application/vnd.ms-excel,' + $('#tabla_datos').html()); e.preventDefault(); });​ 

它工作得很好,但是当我添加一个属性到我的表中的任何元素,如rowspan或colspan,Excel不能正确导出。

这是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 " />​ 

这里是jsfiddle: http : //jsfiddle.net/WAR2v/

有点迟了,但你是否尝试编码你的URI?

这段代码适用于我:

 $("#btnExport").click(function(e) { window.open('data:application/vnd.ms-excel,' + encodeURIComponent($('#tabla_datos').html())); e.preventDefault(); });