You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
zhky/web/print_excel.jsp

68 lines
2.2 KiB

1 year ago
<%@page language="java" pageEncoding="utf-8"%>
<style>
@media screen{.onlyPrint{display:none}}
@media print{
.NotPrint{display:none;}
.PageNext{page-break-after: always;}
}
input {
color: #000000;
background-color: #F7F7F7;
font-size: 12px;
border: 1px solid navy;
padding-bottom: 1px;
}
</style>
<center class="NotPrint">
<OBJECT id=WebBrowser
classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 width=0>
</OBJECT>
<input type=button value="直接打印" onclick=document.all.WebBrowser.ExecWB(6,6)>
<input type=button value="页面设置" onclick=document.all.WebBrowser.ExecWB(8,1)>
<input type=button value="打印预览" onclick=document.all.WebBrowser.ExecWB(7,1)>
<input type=button value="导出Excel" onclick="return exportExcel()">
</center>
<script>
function exportExcel(){
var fileName = "";
if(document.getElementById("filename")==null){
alert("缺少文件名前缀!");
return false;
}else{
fileName = document.getElementById("filename").value;
}
if(document.getElementById("excelData")==null){
alert("导出Excel格式Table的id必须命名为excelData");
return false;
}else if(document.getElementById("excelData").tagName.toUpperCase()!="TABLE"){
alert("导出Excel格式Table的id必须命名为excelData");
return false;
}
if (typeof(EXPORT_OBJECT)!="object"){
document.body.insertAdjacentHTML("afterBegin","<OBJECT style='display:none' classid=clsid:0002E510-0000-0000-C000-000000000046 id=EXPORT_OBJECT></Object>");
}
var now = new Date();
var year = now.getYear();
var month = now.getMonth()+1;
var date = now.getDate();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds();
var ms = now.getMilliseconds();
var sysdate = ''+year+month+date+hours+minutes+seconds+ms;
fileName = "C:\\"+fileName +"_"+sysdate+".xls";
with (EXPORT_OBJECT){
DataType = "HTMLData";
HTMLData =excelData.outerHTML;
try{
ActiveSheet.Export(fileName,0);
alert('导出EXCEL文档完毕');
} catch (e){
alert('导出Excel表失败请确定已安装Excel2000(或更高版本),并且没打开同名xls文件');
}
}
}
</script>