Print.asp
------------------------------------------------
<html><title>打印Excel报表</title>
<%
´控制脚本语言
response.write"<script language="&"VBScript"&">"
%>
//*****************本程序由火星工作室提供(andy2001p@hotmail.com)******************
//*******************版权所有 随意拷贝********************************
function ccprint()
Set xlApp = CreateObject("EXCEL.APPLICATION")
//打开工作表!
Set xlBook = xlApp.Workbooks.Open("c:/book1.xlt")
set xlsheet1 = xlBook.ActiveSheet
<% db="zhk.mdb"
Set conn = Server.CreateObject("ADODB.Connection")
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(""&db&"")
conn.Open connstr
set rsd=server.createobject("adodb.recordset")
str="select * from cjb00"
rsd.open str,conn
ii=1
do while not rsd.eof and ii<11
%>
<%response.write"xlSheet1.cells("&ii 4&",2).value="%>"<%=rsd("姓名")%>"
<%response.write"xlSheet1.cells("&ii 4&",3).value="%>"<%=rsd("学号")%>"
<%
rsd.movenext
ii=ii 1
loop
rsd.close
set rsd=nothing
%>
xlSheet1.Application.Visible = True
end function
//*****************本程序由火星工作室提供******************
<%
response.write"</script>"
%>
<html><title>打印Excel报表</title>
<body>
<center>
<h2><font color=red>学生表(Demo)</font></h2>
<p> </p>
<form name="fmp" method="post" action="">
<%
db="zhk.mdb"
Set conn = Server.CreateObject("ADODB.Connection")
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(""&db&"")
conn.Open connstr
set rsd=server.createobject("adodb.recordset")
str="select * from cjb00"
rsd.open str,conn
%>
<table width="396" height="58" border="1" bordercolor="#00FF00" bgcolor=lightyellow>
<tr bgcolor=deepskyblue>
<th><b>姓名</b></th>
<th><b>学号</b></th>
</tr>
<%
do while not rsd.eof
%>
<tr align=center>
<td> <%=rsd("姓名")%>
</td>
<td> <%=rsd("学号")%>
</td>
</tr>
<%
rsd.MoveNext
loop
%>
<% rsd.close
set rsd=nothing
conn.close
set cnn=nothing %>
</table>
<p>
<input name="Submit2" type="button" οnclick="ccprint()" onDblClick="ccprint()" value="打印">
<br>
</p>
</form>
</center>
</body>
</html>
------------------------------------------------------------
在程序写好后,你必须在 C 盘根目录下建个Excel模板文件! 在IE的安全设置中将安全级别调为最低或自定义安全级别中启用第二项,因为只有这样,IE才能创建EXCEL对象!