<html><head><metahttp-equiv="Content-Type"content="text/html; charset=utf-8"/>
<scripttype="text/javascript">
注:此段代码来自网络,我增加了一些调试(stackoverflow)
vartableToExcel =(function() {
varuri ='data:application/vnd.ms-excel;base64,';
vartemplate ='<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>';
varbase64 =function(s) {returnwindow.btoa(unescape(encodeURIComponent(s))) };
varformat =function(s, c) {returns.replace(/{(\w+)}/g,function(m, p) {returnc[p]; }) };
returnfunction(table, name) {
if(!table.nodeType) table=document.getElementById(table)
varctx ={worksheet: name||'Worksheet', table: table.innerHTML}
alert(table.innerHTML);
window.location.href =uri+base64(format(template, ctx))
}
})();
</script>
<title>下载</title>
</head>
<body>
br/><inputtype="button"
onclick="tableToExcel('ExportTab','hello')"value="导出excel"/>
<tableid="ExportTab"name="ExportTab"width="400"
align="center"cellpadding="0"cellspacing="0">
<tr><tdcolspan="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>
我这里暂时有乱码问题,后续解决再更博