当前位置: 代码迷 >> Web前端 >> 页眼生成EXCEL
  详细解决方案

页眼生成EXCEL

热度:186   发布时间:2012-10-29 10:03:53.0
页面生成EXCEL

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<title>导出为excel 之我的方法</title>
<style type="text/css" rel="stylesheet">
TABLE {border-top:#CCCCCC 2px solid; border-left:#CCCCCC 4px solid; font-size:18px;}
br {mso-data-placement:same-cell;}
td {border-bottom:#CCCCCC 1px solid; border-right:#CCCCCC 1px solid; text-align:left;}
body{
margin:0px;
font-size:15px;
SCROLLBAR-FACE-COLOR: #f6f6f6;
SCROLLBAR-HIGHLIGHT-COLOR: #ffffff;
SCROLLBAR-SHADOW-COLOR: #cccccc;
SCROLLBAR-3DLIGHT-COLOR: #cccccc;
SCROLLBAR-ARROW-COLOR: #330000;
SCROLLBAR-TRACK-COLOR: #f6f6f6;
SCROLLBAR-DARKSHADOW-COLOR: #ffffff;
}

a {
color:blue;
text-decoration:none;
}
a:hover{
color:black;
text-decoration:underline;
}
input{
border:blue solid 1px;
}
#titletr {
??? Z-Index:102;??
??? position:relative;??
??? Top:expression(this.offsetParent.scrollTop);
left:-1px;
background:#CCFF99;
}
</style>
</head>
<SCRIPT LANGUAGE="JavaScript">
<!--
function doSave(obj) {
//alert(document.getElementById('theexecel').innerHTML);
var winname = window.open('', 'excel1', 'top=0');
winname.document.open('text/html', 'replace');
execelcontent=document.getElementById('theexecel').innerHTML
winname.document.writeln(execelcontent);
winname.document.execCommand('saveas','','导出的excel.xls');
winname.close();
}
//-->
</SCRIPT>
<SCRIPT LANGUAGE="javascript">
function AllAreaExcel()
{
var oXL = new ActiveXObject("Excel.Application");
var oWB = oXL.Workbooks.Add();
var oSheet = oWB.ActiveSheet;
var sel=document.body.createTextRange();
sel.moveToElementText(excel2);
//sel.select();
sel.execCommand("Copy");
oSheet.Paste();
oXL.Visible = true;
}

</SCRIPT>
<iframe id="excel1" name="excel1" width="0" height="0"></iframe>

<INPUT TYPE="button" VALUE="保存到EXCEL" ONCLICK="doSave('theexecel')">
<INPUT TYPE="button" VALUE="Excel 查看" ONCLICK="AllAreaExcel()">
<INPUT TYPE="BUTTON" value="本页存为.." onclick="javascript:document.all.save.ExecWB(4,1)">

<OBJECT CLASSID=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 ID="save" HEIGHT=0 WIDTH=0>
</OBJECT>

<div id="theexecel" name="theexecel" style="height:100%;">
<table cellpadding="0" cellspacing="0" align="center" id="excel2" name="excel2" width='990'>
<TR>
<TD>q</TD>
<TD>w</TD>
<TD>w</TD>
<TD>w</TD>
</TR>
<TR>
<TD>w</TD>
<TD>w</TD>
<TD>w</TD>
<TD>w</TD>
</TR>
<TR>
<TD>w</TD>
<TD>w</TD>
<TD>w</TD>
<TD>w</TD>
</TR>
<TR>
<TD>e</TD>
<TD>e</TD>
<TD>e</TD>
<TD>e</TD>
</TR>
</TABLE>
</div>
</body>
</html>

  相关解决方案