A new way to print Excel reports in an ASP program
at present, b/S mode (browser/server mode) has become the preferred computing mode of the Enterprise network. Because of the particularity of B/S mode, the Excel report printing function which is relatively easy to realize under C/S is a difficult problem under B/S. I have written a program based on ASP program to print Excel report. This procedure is characterized by no need for any components.
print.asp
------------------------------------------------
<%
' Control scripting language
Response.Write "<script language=" & "VBScript" & ">"
%>
This procedure is provided by the Mars Studio (andy2001p@hotmail.com) ******************
All rights reserved FREE copy ********************************
function Ccprint ()
Set xlapp = CreateObject ("EXCEL. Application ")
//Open the worksheet! &NBSP
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& "") &NBSP
Conn. Open connstr
Set Rsd=server.createobject ("Adodb.recordset")
str= "select * from cjb00" &NBSP;
Rsd.open str,conn
ii=1
do, not rsd.eof and ii<11
%>
<% Response.Write "Xlsheet1.cells (" &ii+4& ", 2). value="%> "<%=RSD (" name ")%>" &NBSP;
<% Response.Write "Xlsheet1.cells" ("&ii+4&", 3). value= "%>" <%=RSD ("School Number")%> "&NBSP;
<%
RSD.MOVENEXT&NBSP
ii=ii+1
loop
rsd.close
set rsd=nothing
%>
XlSheet1.Application.Visible = true
End function
//***************** This program is provided by the Mars Studio ************
<%
Response.Write "</script>"
%>
<body>
<center>
<p> </p> &NBSP
<form name= "FMP" method= "POST" action= "" >&NBSP;
<%
db= "Zhk.mdb" &NBSP;
Set conn = Server.CreateObject ("ADODB.") Connection ")
connstr=" Provider=Microsoft.Jet.OLEDB.4.0;Data source= "& Server.MapPath (" "&db& "") &NBSP
Conn. Open connstr
Set Rsd=server.createobject ("Adodb.recordset")
str= "select * from cjb00" &NBSP;
Rsd.open str,conn
%>
<table width= "396" height= "" border= "1" bordercolor= "#00FF00" bgcolor =LIGHTYELLOW>&NBSP
<tr bgcolor=deepskyblue>
<th><b> name </b></th> &NBSP
<th><b> </b></th>
</tr>
<%
Do RSD.EOF&NBSP
%>
<tr ALIGN=CENTER>&NBSP
<td> <%=rsd ("name")%>
</td>
<td> <%=rsd ("School Number" )%>
</td>
</tr>
<%
RSD. MOVENEXT&NBSP
loop
%>
<% rsd.close
set rsd=nothing
Conn.close &NBSP
Set cnn=nothing%>
</table>
<p>
<input name= "Submit2" type= "Button" onclick= "Ccprint ()" ondblclick= "Ccprint ()" value= "print" >&NBSP;
<br>
</p>
</form>
</center>
</body>