当前位置: 首页 > 图文教程 > 网络编程 > ASP > 利用ASP在浏览器上打印输出

ASP
asp 实现对SQL注入危险字符进行重编码处理的函数
asp下实现对HTML代码进行转换的函数
asp 验证用户名是否包含有非常字符的函数
ASP通用分页样式函数代码
asp 生成任意英文+数字位数长度的随机码函数
asp 取得中文句子头一个字的大写拼音字母的函数
asp实现计算两个时间内的工作日的函数
asp实现过滤关键字的函数
asp实现限制搜索的关键字的函数
asp动态include文件,方便多模板的实现
推荐的用Asp实现屏蔽IP地址访问的代码
XDOWNPAGE ASP版本 分页类
飞云防CC攻击ASP程序代码插件
定期自动运行ASP程式的代码
ASP下Cookie操作的详细讲解
再发几个ASP不错的函数
比较不错的asp模板引终极讲解(WEB开发之ASP模式)
ip138之asp小偷程序代码
在VBScript中实现-函数/方法名作为参数传入另一个函数
asp实现批量插入表单中的数据到数据库的方法

利用ASP在浏览器上打印输出


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 205 ::
收藏到网摘: n/a

  利用asp结合javascript或vbscript可以生成动态的web页面。在将这种方法用于实际应用中时,不可避免的要将结果打印输出。我们同样可以将查询结果整理后输出,并用浏览器工具栏上的打印按钮直接打印输出。以下程序是访问sql server 自带的数据库pubs中的sales表,服务器和工作站端都采用vbscript。当工作站端采用javascript时,可用navigator访问。

〈html〉〈head〉

〈meta http-equiv=″content-type″ content=″text/html; charset=gb—2312-80″〉

〈meta name=″vi60—defaultclientscript″ content=″vbscript″〉

〈meta name=″generator″ content=″microsoft frontpage 3.0″〉

〈title〉sales〈/title〉〈/head〉

〈body〉〈form〉

〈table border=″0″ width=″800″ cellspacing=″0″ cellpadding=″0″〉

′定义表宽800点

〈tr〉〈td〉〈div align=″center″〉〈center〉〈h2〉〈strong〉订单报表〈/strong〉〈/h2〉

〈/center〉〈/div〉〈/td〉〈/tr〉〈tr〉〈td〉〈div align=″right″〉〈p〉单位:元 〈/td〉〈/tr〉〈/table〉

〈table border=″1″ width=″800″ cellspacing=″0″ cellpadding=″0″〉〈tr〉

〈td width=″25%″ align=″center″〉stor_id

〈/td〉〈td width=″25%″ align=″center″〉ord_num〈/td〉

〈td width=″25%″ align=″center″〉ord_date〈/td〉〈td width=″25%″ align=″center″〉qty〈/td〉〈/tr〉〈% set cn=server.createobject(″adodb.connection″)

′定义一个ado的连接对象

cn.open ″provider=sqloledb;data source=202.203.208.1;initial catalog=pubs;user id=sa;password=; ″

′定义数据库连接

sql=″select stor_id,ord_num,ord_date,qty from sales where ord_date〉′1994-5-1′″

set rs=cn.execute(sql)

while not rs.eof

′判断是否为最后一条记录

qtyv=rs(″qty″)

sumqtyv=sumqtyv+qtyv%〉

〈tr〉〈td〉〈%=rs(″stor_id″)%〉〈/td〉

〈td〉〈%=rs(″ord_num″)%〉〈/td〉

〈td〉〈%=rs(″ord_date″)%〉〈/td〉

〈td〉〈%=qtyv%〉〈/td〉〈/tr〉

〈%rs.movenext ′移动到下一条记录wend%〉〈tr〉

〈td colspan=″3″〉合计〈/td〉

〈td〉〈%=sumqtyv%〉〈/td〉

〈/tr〉〈/table〉〈%cn.close%〉〈/form〉〈/body〉〈/html〉  


为保证能打印各种大小的报表,可先将浏览器中打印设置的纸张大小定为最宽,然后通过调整〈table width=″″〉的值输出不同的报表大小。