我有以下示例代码将html内容导出为excel。它在Chrome浏览器中运行良好。但它不适用于任何IE浏览器8/9版本。请参考下面的代码。
<html>
<head>
<script src="http://code.jquery.com/jquery-1.11.1.js"></script>
<script>
$(document).ready(function() {
$("[id$=excellink]").click(function(e) {
alert("$('div[id$=dvData]').html()");
window.open('data:application/vnd.xls,' + encodeURIComponent( $('div[id$=dvData]').html()));
e.preventDefault();
});
});
</script>
<body>
<br/>
<div id="dvData">
<table>
<tr>
<th>Billing System</th>
<th>Market Code</th>
<th>Payment Amount</th>
</tr>
<tr>
<td>RED</td>
<td>222</td>
<td>$103.00</td>
</tr>
<tr>
<td>BLUE</td>
<td>111</td>
<td>$13.00</td>
</tr>
<tr>
<td>GREEN</td>
<td>555</td>
<td>$143.00</td>
</tr>
</table>
</div>
<br/>
<input type="button" id="excellink" value="Excel" />
</body>
</head>
</html>