【发布时间】:2012-12-06 02:45:01
【问题描述】:
我正在尝试使用我在互联网上找到的这个简单功能将 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/
【问题讨论】:
-
我在打开文件时也面临同样的问题,它会生成错误,即文件的格式可能与指定的不同,即“xsl”,并且此生成的 excel 的网格线也不会消失.......
标签: jquery html excel html-table