关于客户端用ASP参生报表

先贴一篇较简单的用ASP+RDS客户端参生报表
此文希望能进精华篇
下一回贴一篇较复杂的
说明:(若提示ActiveX 元件无法参生 RDS.DataSpace)
IE需设置安全选项
操作:菜单工具->INTERNET选项->安全性->自定义
设置 起始但ActiveX不标示为安全->开启

 1<html>
 2<head>
 3<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
 4<title>client use rds produce excel report</title>
 5<link href="cdutmenu/common.css" rel="stylesheet"/>
 6</head>
 7<body bgcolor="skyblue" bottommargin="0" leftmargin="20" oncontextmenu="return false" rightmargin="0" topmargin="5">
 8<div align="center"><center>
 9<table bgcolor="#ffe4b5" border="1" bordercolor="#0000ff" style="HEIGHT: 1px; TOP: 0px">
10<tr>
11<td align="middle" bgcolor="#ffffff" bordercolor="#000080">
12<font color="#000080" size="3">   
13client use rds produce excel report   
14</font>
15</td>
16</tr>
17</table>
18</center></div>
19<form action="long.asp" method="post" name="myform">
20<div align="left">
21<input language="vbscript" name="query" onclick="fun_excel(1)" style="HEIGHT: 32px; WIDTH: 90px" type="button" value="Query Data"/>
22<input language="vbscript" name="Clear" onclick="fun_excel(2)" style="HEIGHT: 32px; WIDTH: 90px" type="button" value="Clear Data"/>
23<input language="vbscript" name="report" onclick="fun_excel(3)" style="HEIGHT: 32px; WIDTH: 90px" type="button" value="Excel Report"/>
24</div>
25<div id="adddata"></div>
26</form>
27</body>
28</html>
 1<script language="vbscript">   
 2sub fun_excel(t)   
 3Dim rds,rs,df   
 4dim strCn,strSQL,StrRs   
 5Dim xlApp, xlBook, xlSheet1   
 6  
 7'use rds to produce client recordset   
 8set rds = CreateObject("RDS.DataSpace")   
 9Set df = rds.CreateObject("RDSServer.DataFactory","http://server name")   
10'the connection string to sql server to query database:pubs--->table:jobs   
11strCn="DRIVER={SQL Server};SERVER=server name;UID=sa;APP=Microsoft Development Environment;DATABASE=pubs;User Id=sa;PASSWORD=;"   
12'the query string of sql   
13strSQL = "Select top 8 * from jobs order by job_id"   
14'the recordset   
15Set rs = df.Query(strCn, strSQL)   
16  
17if t=1 then   
18if not rs.eof then   
19StrRs="<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>"   
20adddata.innerHTML=StrRs   
21StrRs=""   
22else   
23msgbox "No data in the table!"   
24end if   
25elseif t=2 then   
26StrRs=""   
27adddata.innerHTML=StrRs   
28elseif t=3 then   
29Set xlApp = CreateObject("EXCEL.APPLICATION")   
30Set xlBook = xlApp.Workbooks.Add   
31Set xlSheet1 = xlBook.Worksheets(1)   
32xlSheet1.cells(1,1).value ="the job table "   
33xlSheet1.range("A1:D1").merge   
34xlSheet1.cells(2,1).value = "job_id"   
35xlSheet1.cells(2,2).value = "job_desc"   
36xlSheet1.cells(2,3).value = "max_lvl"   
37xlSheet1.cells(2,4).value = "min_lvl"   
38cnt = 3   
39'adapt to office 97 and 2000   
40do while not rs.eof   
41xlSheet1.cells(cnt,1).value = rs("job_id")   
42xlSheet1.cells(cnt,2).value = rs("job_desc")   
43xlSheet1.cells(cnt,3).value = rs("max_lvl")   
44xlSheet1.cells(cnt,4).value = rs("min_lvl")   
45rs.movenext   
46cnt = cint(cnt) + 1   
47loop   
48xlSheet1.Application.Visible = True   
49  
50'adapt to office 2000 only   
51'xlSheet1.Range("A3").CopyFromRecordset rs   
52'xlSheet1.Application.Visible = True   
53end if   
54end sub   
55</script>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus