[英]Can't export HTML table to Excel when using attributes on the table elements
我正在嘗試使用在互聯網上找到的這個簡單功能將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();
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.