使用XML+VBS技术在ASP中实现报表的打印
网络整理 - 07-26
一、前言ASP在电子商务上应用广泛,报表的处理又有一些麻烦。本文介绍了在ASP中利用
本人写的Report Server Page脚本解释器实现报表的显示、打印。
二、准备工作
(1)安装Visual Reprort Design软件
Visual Report Design是本人写的一个免费的报表设计器,程序的发行只需要
安装一个控件即可。
想要的网友可以到 下载
(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
ReportName=Server.MapPath("mxb.vbs")
ret=reportatl.Dos cript(ReportName)
if ret=-1 then
response.write reportatl.ErrorMsg
set ReportAtl=nothing
response.end
end if
set ReportAtl=nothing
%>
<html>
<OBJECT id=reportatl classid="clsid:D3F064E5-F4C0-4C52-9E7F-263D96B7EA11" codebase="Report.cab#version=1,0,0,1">
</OBJECT>
<s cript language=vbs cript>
dim ret
ret=reportatl.DoPrintReport("mxb.zcg")
if ret=-1 then
msgbox reportatl.ErrorMsg
end if
</s cript>
</html>
用Visual Report Design 产生的报表脚本mxb.rsp:
<?xml version='1.0' encoding='GB2312' ?>
<!DOCTYPE report SYSTEM 'print_report.dtd' >
<report>
<report_s cript>
dim rs,con,sql,lsh
dim temp
set con =CreateObject("ADODB.Connection")
con.ConnectionString = "DBQ=c:reportdemoaspreport.mdb;DRIVER={Microsoft Access Driver (*.mdb)};"
con.open
Set rs =CreateObject("ADODB.Recordset")
sql="SELECT * FROM cj,student where cj.id=student.id "
rs.open sql,con,1,3
</report_s cript>
<report_head>
<text top='4' left='76' font_name='宋体' font_size='14' font_weight='700' font_italic='0' font_underline='0' >
成绩明细表
</text>
</report_head>
<page_head>
<line top='0' left='9' weight='131072'>
</line>
<line top='6' left='9' weight='131072'>
</line>
<text top='2' left='18' font_name='宋体' font_size='9' font_weight='700' font_italic='0' font_underline='0' >
姓名
</text>
<text top='2' left='46' font_name='宋体' font_size='9' font_weight='700' font_italic='0' font_underline='0' >
语文
</text>
<text top='2' left='72' font_name='宋体' font_size='9' font_weight='700' font_italic='0' font_underline='0' >
数学
</text>
<text top='2' left='99' font_name='宋体' font_size='9' font_weight='700' font_italic='0' font_underline='0' >
英语
</text>
<text top='2' left='162' font_name='宋体' font_size='9' font_weight='700' font_italic='0' font_underline='0' >
合计
</text>
<text top='2' left='130' font_name='宋体' font_size='9' font_weight='700' font_italic='0' font_underline='0' >
平均
</text>
</page_head>
<page_body>
<text top='2' left='15' font_name='宋体' font_size='9' font_weight='100' font_italic='0' font_underline='0' >
<report_s cript>
Report.Write cstr(rs("xm"))
</report_s cript>
</text>
<text top='2' left='45' font_name='宋体' font_size='9' font_weight='100' font_italic='0' font_underline='0' >
<report_s cript>
Report.Write cstr(rs("yw"))
</report_s cript>
</text>
<text top='2' left='71' font_name='宋体' font_size='9' font_weight='100' font_italic='0' font_underline='0' >
<report_s cript>
Report.Write cstr(rs("sx"))
</report_s cript>
</text>
<text top='2' left='98' font_name='宋体' font_size='9' font_weight='100' font_italic='0' font_underline='0' >
<report_s cript>
Report.Write cstr(rs("yy"))
</report_s cript>
</text>
<text top='2' left='130' font_name='宋体' font_size='9' font_weight='100' font_italic='0' font_underline='0' >
<report_s cript>
Report.Write cstr((rs("yw")+rs("sx")+rs("yy"))/3)
</report_s cript>
</text>
<text top='2' left='162' font_name='宋体' font_size='9' font_weight='100' font_italic='0' font_underline='0' >
<report_s cript>
Report.Write cstr(rs("yw")+rs("sx")+rs("yy"))
</report_s cript>
</text>
</page_body>
<page_foot>
<text top='2' left='12' font_name='宋体' font_size='9' font_weight='100' font_italic='0' font_underline='0' >
<report_s cript>
report.write "打印日期:"+formatdatetime(date(),1)
</report_s cript>
</text>
<text top='2' left='137' font_name='宋体' font_size='9' font_weight='100' font_italic='0' font_underline='0' >
共%Pages%页,第%Page%页
</text>
<line top='0' left='8' weight='131072'>
</line>
</page_foot>
<report_s cript>
do while not rs.eof
page_body()
rs.movenext
loop
rs.close
set rs=nothing
con.close
set con=nothing
</report_s cript>
</report>
四、其它信息
这是本人第一个开发工具,做得不好请指教
详细情况可以看:
关于在ASP下使用的详细例子可以看c:demoasp/目录