欢迎光临
我们一直在努力

一篇关于客户端用ASP参生报表的好东东

建站超值云服务器,限时71元/月

先贴一篇较简单的用asp+rds客户端参生报表
此文希望能进精华篇
下一回贴一篇较复杂的
说明:(若提示activex 元件无法参生 rds.dataspace)
ie需设置安全选项
操作:菜单工具->internet选项->安全性->自定义
设置  起始但activex不标示为安全->开启   
<html>
<head>
<meta content="text/html; charset=gb2312" http-equiv=content-type>
<title>client use rds produce excel report</title>
<link rel="stylesheet" href="cdutmenu/common.css">
</head>
<body bgcolor=skyblue topmargin=5 leftmargin="20" oncontextmenu="return false" rightmargin=0 bottommargin="0">

<div align="center"><center>        
<table border="1" bgcolor="#ffe4b5" style="height: 1px; top: 0px" bordercolor="#0000ff">
    <tr>
         <td align="middle" bgcolor="#ffffff" bordercolor="#000080">
         <font color="#000080" size="3">    
         client use rds produce excel report
         </font>
         </td>
    </tr>
</table>
</div>

<form action="long.asp" method="post" name="myform">
<div align=left>
<input type="button" value="query data"   name="query"  language="vbscript" onclick="fun_excel(1)"  style="height: 32px; width: 90px">
<input type="button" value="clear data"   name="clear"  language="vbscript" onclick="fun_excel(2)"  style="height: 32px; width: 90px">
<input type="button" value="excel report" name="report" language="vbscript" onclick="fun_excel(3)"  style="height: 32px; width: 90px">
</div>
<div id="adddata"></div>
</form>
</body>
</html>

<script language="vbscript">
sub fun_excel(t)
    dim rds,rs,df               
    dim  strcn,strsql,strrs
    dim xlapp, xlbook, xlsheet1

use rds to produce client recordset  
    set rds = createobject("rds.dataspace")
    set df = rds.createobject("rdsserver.datafactory","http://server name")
the connection string to sql server to query database:pubs—>table:jobs
    strcn="driver={sql server};server=server name;uid=sa;app=microsoft development environment;database=pubs;user id=sa;password=;"
the query string of sql
    strsql = "select top 8 * from jobs order by job_id"
the recordset
    set rs = df.query(strcn, strsql)
   
    if t=1 then  
       if not rs.eof then
          strrs="<table border=1><tr><td>job_id</td><td>job_desc</td><td>max_lvl</td><td>min_lvl</td></tr><tr><td>"+ rs.getstring(,,"</td><td>","</td></tr><tr><td>"," ") +"</td></tr></table>"   
          adddata.innerhtml=strrs
          strrs=""
       else
          msgbox "no data in the table!"  
       end if
    elseif t=2 then      
          strrs=""
          adddata.innerhtml=strrs
    elseif t=3 then      
       set xlapp = createobject("excel.application")
       set xlbook = xlapp.workbooks.add
       set xlsheet1 = xlbook.worksheets(1)
       xlsheet1.cells(1,1).value ="the job  table "
       xlsheet1.range("a1:d1").merge
       xlsheet1.cells(2,1).value = "job_id"
       xlsheet1.cells(2,2).value = "job_desc"
       xlsheet1.cells(2,3).value = "max_lvl"
       xlsheet1.cells(2,4).value = "min_lvl"
       cnt = 3
adapt to office 97 and 2000
       do while not rs.eof
          xlsheet1.cells(cnt,1).value = rs("job_id")
          xlsheet1.cells(cnt,2).value = rs("job_desc")
          xlsheet1.cells(cnt,3).value = rs("max_lvl")
          xlsheet1.cells(cnt,4).value = rs("min_lvl")
          rs.movenext
          cnt = cint(cnt) + 1
       loop
       xlsheet1.application.visible = true
       
adapt to office 2000 only
        xlsheet1.range("a3").copyfromrecordset rs
        xlsheet1.application.visible = true
    end if
end sub
</script>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 一篇关于客户端用ASP参生报表的好东东
分享到: 更多 (0)

相关推荐

  • 暂无文章