<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 1.0 Transitional//EN">
<html>
<head>
……
</head>
<body>
<div id="layout" class="easyui-layout" fit="true">
<div >
<a id='dLink' style="display:none" href="#">链接</a>
</div>
<div>
<table id="dg">
<thead id="dgHead"></thead>
<tbody id="dgBody"></tbody>
</table>
</div>
</div>
</body>
</html>
function exportExcel(){
tableToExcel('dg', 'name', '数据统计报表.xls');
}
function base64(content){
return window.btoa( unescape( encodeURIComponent(content) ) )
}
function tableToExcel(table, name, filename){
try{
var uri = 'data:application/vnd.ms-excel;base64,';
var table = document.getElementById(table);
var excelContent = table.innerHTML;
var excelFile = '<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><body><table border="1">'+excelContent+'</table></body></head></html>';
$.messager.confirm('提示', '由于导出时间比较长,是否确定导出单位考核数据?', function(r) {
if (r) {
document.getElementById('dLink').href = uri + base64(excelFile);
document.getElementById('dLink').download = filename;
document.getElementById('dLink').click();
}
});
}catch(err){
alert(err);
}
}