A new way to print Excel reports in an ASP program

Source: Internet
Author: User
excel| Program | Print 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!
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, not rsd.eof and ii<11
%>
<%response.write "Xlsheet1.cells (" &ii+4& ", 2). value="%> "&LT;%=RSD (" name ")%>"
<%response.write "Xlsheet1.cells" ("&ii+4&", 3). value= "%>" &LT;%=RSD ("School Number")%> "
<%
Rsd.movenext
Ii=ii+1
Loop
Rsd.close
Set rsd=nothing
%>
XlSheet1.Application.Visible = True
End Function
This procedure is provided by the Mars Studio ******************
<%
Response.Write "</script>"
%>


<body>
<center>
<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= "border=" "1" bordercolor= "#00FF00" bgcolor=lightyellow>
<tr bgcolor=deepskyblue>
<th><b> name </b></th>
<th><b> School Number </b></th>
</tr>
<%
Do as not rsd.eof
%>
<tr align=center>
<td> <%=rsd ("name")%>
</td>
<td> &LT;%=RSD ("School Number")%>
</td>
</tr>
<%
Rsd. MoveNext
Loop
%>
<% Rsd.close
Set rsd=nothing
Conn.close
Set Cnn=nothing%>
</table>
<p>
<input name= "Submit2" type= "button" onclick= "Ccprint ()" ondblclick= "Ccprint ()" value= "Print" >
<br>
</p>
</form>
</center>
</body>

------------------------------------------------------------

After the program is written, you must build an Excel template file in the C-packing directory! In IE's security settings, the security level is set to the minimum or custom security level to enable the second item, because only in this way, ie can create an Excel object!

This procedure is provided by Andylee (MARS), if you have any comments please contact:
Email:andy2001p@hotmail.com
qq:16685104
tel:0595-2092139



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.