首页 > 开发 > XML > 正文

使用XML VBS技术在ASP中实现报表的打印

2024-09-05 20:55:42
字体:
来源:转载
供稿:网友
菜鸟学堂:
一、前言
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

reportname=server.mappath("mxb.vbs")
ret=reportatl.doscript(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>
<script language=vbscript>
dim ret
ret=reportatl.doprintreport("mxb.zcg")
if ret=-1 then
msgbox reportatl.errormsg
end if
</script>
</html>

用visual report design 产生的报表脚本mxb.rsp:

<?xml version='1.0' encoding='gb2312' ?>

<!doctype report system 'print_report.dtd' >

<report name='报表'>

<report_script>

dim rs,con,sql,lsh
dim temp
set con =createobject("adodb.connection")
con.connectionstring = "dbq=c:/report/demo/asp/report.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_script>

<report_head height='12'>

<text name='vfptext' top='4' left='76' width='26' height='5' font_name='宋体' font_size='14' font_weight='700' font_italic='0' font_underline='0' >

成绩明细表

</text>

</report_head>

<page_head height='6'>

<line name='vfpline' top='0' left='9' width='178' height='0' weight='131072'>

</line>

<line name='vfpline' top='6' left='9' width='178' height='0' weight='131072'>

</line>

<text name='vfptext' top='2' left='18' width='6' height='3' font_name='宋体' font_size='9' font_weight='700' font_italic='0' font_underline='0' >

姓名

</text>

<text name='vfptext' top='2' left='46' width='6' height='3' font_name='宋体' font_size='9' font_weight='700' font_italic='0' font_underline='0' >

语文

</text>

<text name='vfptext' top='2' left='72' width='6' height='3' font_name='宋体' font_size='9' font_weight='700' font_italic='0' font_underline='0' >

数学

</text>

<text name='vfptext' top='2' left='99' width='6' height='3' font_name='宋体' font_size='9' font_weight='700' font_italic='0' font_underline='0' >

英语

</text>

<text name='vfptext' top='2' left='162' width='6' height='3' font_name='宋体' font_size='9' font_weight='700' font_italic='0' font_underline='0' >

合计

</text>

<text name='vfptext' top='2' left='130' width='6' height='3' font_name='宋体' font_size='9' font_weight='700' font_italic='0' font_underline='0' >

平均

</text>

</page_head>

<page_body height='8'>

<text name='vfptext' top='2' left='15' width='25' height='4' font_name='宋体' font_size='9' font_weight='100' font_italic='0' font_underline='0' >

<report_script>

report.write cstr(rs("xm"))

</report_script>

</text>

<text name='vfptext' top='2' left='45' width='18' height='4' font_name='宋体' font_size='9' font_weight='100' font_italic='0' font_underline='0' >

<report_script>

report.write cstr(rs("yw"))

</report_script>

</text>

<text name='vfptext' top='2' left='71' width='18' height='4' font_name='宋体' font_size='9' font_weight='100' font_italic='0' font_underline='0' >

<report_script>

report.write cstr(rs("sx"

|||

))

</report_script>

</text>

<text name='vfptext' top='2' left='98' width='18' height='4' font_name='宋体' font_size='9' font_weight='100' font_italic='0' font_underline='0' >

<report_script>

report.write cstr(rs("yy"))

</report_script>

</text>

<text name='vfptext' top='2' left='130' width='18' height='4' font_name='宋体' font_size='9' font_weight='100' font_italic='0' font_underline='0' >

<report_script>

report.write cstr((rs("yw")+rs("sx")+rs("yy"))/3)

</report_script>

</text>

<text name='vfptext' top='2' left='162' width='18' height='4' font_name='宋体' font_size='9' font_weight='100' font_italic='0' font_underline='0' >

<report_script>

report.write cstr(rs("yw")+rs("sx")+rs("yy"))

</report_script>

</text>

</page_body>

<page_foot height='7'>

<text name='vfptext' top='2' left='12' width='13' height='3' font_name='宋体' font_size='9' font_weight='100' font_italic='0' font_underline='0' >

<report_script>

report.write "打印日期:"+formatdatetime(date(),1)

</report_script>

</text>

<text name='vfptext' top='2' left='137' width='50' height='3' font_name='宋体' font_size='9' font_weight='100' font_italic='0' font_underline='0' >

共%pages%页,第%page%页

</text>

<line name='vfpline' top='0' left='8' width='178' height='0' weight='131072'>

</line>

</page_foot>

<report_script>

do while not rs.eof
page_body()
rs.movenext
loop
rs.close
set rs=nothing
con.close
set con=nothing

</report_script>


</report>

四、其它信息
这是本人第一个开发工具,做得不好请指教
详细情况可以看:http://go.163.com/reportpro/
关于在asp下使用的详细例子可以看c:/demo/asp/目录

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表