<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
注:此段代码来自网络,我增加了一些调试(stackoverflow)
var tableToExcel = (function() {
var uri = 'data:application/vnd.ms-excel;base64,';
var template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head></head><body><table>{table}</table></body></html>';
var base64 = function(s) {return window.btoa(unescape(encodeURIComponent(s))) };
var format = function(s, c) {return s.replace(/{(\w+)}/g,function(m, p) {return c[p]; }) };
return function(table, name) {
if (!table.nodeType) table= document.getElementById(table)
var ctx = {worksheet: name|| 'Worksheet', table: table.innerHTML}
alert(table.innerHTML);
window.location.href = uri+ base64(format(template, ctx))
}
})();
</script>
<title>下载</title>
</head>
<body>
br /><input type="button"
onclick="tableToExcel('ExportTab','hello')" value="导出excel"/>
<table id="ExportTab" name="ExportTab" width="400"
align="center" cellpadding="0" cellspacing="0" >
<tr><td colspan="4">电子病历数据</td></tr><
tr><td>测试类型</td><td>测试文件数</td><td>正确比例</td><td>空比例</td><td>错误比例</td></tr>
<tr><td>文件1</td><td>1</td><td>73/148</td><td>67/148</td><td>8/148</td></tr>
<tr><td>文件2</td><td>1</td><td>19/27</td><td>8/27</td><td>0/27</td></tr>
</table>
</body>
</html>
我这里暂时有乱码问题,后续解决再更博