首页 > 网站 > 建站经验 > 正文

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

2019-11-02 15:13:11
字体:
来源:转载
供稿:网友

   利用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&

历史人物故事[www.9-39.com/html/person/]
Prime;)

  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=″″〉的值输出不同的报表大小。

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