Dim strSubmit 'Form中用来保存提交按钮的值
Dim strPrinterPath 'Form中保存网络打印机路径的值
Dim strUsername 'Form中用户名的值
Dim strPassword 'Form中密码的值
Dim strMessage 'Form打印内容的值
Dim objFS 'VBScript中的文件系统对象
Dim objWSHNet 'WSH中的网络对象
Dim objPrinter '打印对象
strSubmit = Request.Form("Submit")
%>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>
We will now use the VBScript FileSystemObject object and the WSH Network object. The Network object will
give us the methods we need to open a printer connection, and the FileSystemObject will allow us to stream our
output to the printer. We create these objects in the following code example:
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objWSHNet = CreateObject("WScript.Network")
' 使用WSH连接网络打印机
objWSHNet.AddPrinterConnection "LPT1", strPrinterPath, False, strUsername, strPassword
' 使用文件系统对象将打印设备作为一个文件使用
Set objPrinter = objFS.CreateTextFile("LPT1:", True)
' 给打印设备送出文本
objPrinter.Write(strMessage)
'关闭打印设备对象并进行错误陷阱处理
On Error Resume Next
objPrinter.Close
' 如果发生错误,关闭打印连接,并输出错误信息
If Err Then
Response.Write ("Error # " & CStr(Err.Number) & " " & Err.Description)
Err.Clear
Else
' 操作成功,输出确认信息
Response.Write("<CENTER>")
Response.Write("<TABLE WIDTH=100% ALIGN=center BORDER=0 CELLSPACING=1 CELLPADDING=1>")
Response.Write("<TR><TD ALIGN=RIGHT><B>打印消息送出:</B></TD>")
Response.Write("<TD ALIGN=LEFT>" & strMessage & "</TD></TR>")
Response.Write("<TR><TD ALIGN=RIGHT><B>网络打印机路径:</B></TD>")
Response.Write("<TD ALIGN=LEFT>" & strPrinterPath & "</TD></TR>")
Response.Write("<TR><TD ALIGN=RIGHT><B>登录帐号:</B></TD>")
Response.Write("<TD ALIGN=LEFT>" & strUsername & "</TD></TR>")
Response.Write("</TABLE>")
Response.Write("</CENTER>")
End If
' 取消打印连接
objWSHNet.RemovePrinterConnection "LPT1:"
Set objWSHNet = Nothing
Set objFS = Nothing
Set objPrinter = Nothing
End If
%>
</BODY>
</HTML>
<!--#include file="include/config.asp"-->
<%
'EXAMPLE AS:把数据库中一个每天24小时在线人数放到一个EXCEL文件中去
'AUTHOR :钢铁工人
'EMAIL :hello_hhb@21cn.com
'DATE :2001-3-25
'TEST :在NT4,SP6,SQL SERVER 7.0,EXCEL2000中测试通过
%>
<HTML>
<HEAD>
<meta content="text/html; charset=gb2312" http-equiv="Content-Type">
<TITLE>生成EXCEL文件</TITLE>
</HEAD>
<body>
<a href="excel.asp?act=make">生成在线人口的EXCEL</a>
<hr size=1 align=left width=300px>
<%
if Request("act") <> "" then
'dim conn
'set conn=server.CreateObject("adodb.connection")
'conn.Open "test","sa",""
'conn.Open Application("connstr")
dim rs,sql,filename,fs,myfile,x,link
Set fs = server.CreateObject("scripting.filesystemobject")
'--假设你想让生成的EXCEL文件做如下的存放
filename = "c:\online.xls"
'--如果原来的EXCEL文件存在的话删除它
if fs.FileExists(filename) then
fs.DeleteFile(filename)
end if
'--创建EXCEL文件
set myfile = fs.CreateTextFile(filename,true)
Set rs = Server.CreateObject("ADODB.Recordset")
'--从数据库中把你想放到EXCEL中的数据查出来
sql = "select username,name,sex from t_user order by id asc"
rs.Open sql,cn,3,1
if not rs.EOF then
dim strLine,responsestr
strLine=""
For each x in rs.fields
strLine= strLine & x.name & chr(9)
Next
'--将表的列名先写入EXCEL
myfile.writeline strLine
Do while Not rs.EOF
strLine=""
for each x in rs.Fields
strLine= strLine & x.value & chr(9)
next
'--将表的数据写入EXCEL
myfile.writeline strLine
rs.MoveNext
loop
end if
rs.Close
'--从数据库中把你想放到EXCEL中的数据查出来
sql1 = "select username1,name1,sex1 from t_usera order by id asc"
rs.Open sql1,cn,3,1
if not rs.EOF then
dim strLine1,responsestr1
strLine1=""
For each x in rs.fields
strLine1= strLine1 & x.name & chr(9)
Next
'--将表的列名先写入EXCEL
myfile.writeline strLine1
Do while Not rs.EOF
strLine1=""
for each x in rs.Fields
strLine1= strLine1 & x.value & chr(9)
next
'--将表的数据写入EXCEL
myfile.writeline strLine1
rs.MoveNext
loop
end if
rs.Close
set rs = nothing
cn.close
set cn = nothing
set myfile = nothing
Set fs=Nothing
link="<A HREF=" & filename & ">Open The Excel File</a>"
Response.write link
end if
%>
</BODY>
</HTML>
一、前言
ASP在电子商务上应用广泛,报表的处理又有一些麻烦。本文介绍了在ASP中利用
本人写的Report Server Page脚本解释器实现报表的显示、打印。
二、准备工作
(1)安装Visual Reprort Design软件
Visual Report Design是本人写的一个免费的报表设计器,程序的发行只需要
安装一个控件即可。
想要的网友可以到http://go.163.com/reportpro/ 下载
(2)设计报表
通过Visual Report Design 的可视化界面可以生成报表的脚本:mxb.rsp。
三、实现报表的打印、显示
下面是调用的文档:
printmx.asp
<%Option Explicit%>
<%
dim ReportName,ret
dim ReportAtl
dim name
set ReportAtl=Session("ReportAtl")
ReportName=Server.MapPath("mxb.rsp")
ret=reportatl.XMLToVBS(ReportName)
if ret=-1 then
response.write reportatl.ErrorMsg
response.end
end if