<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" οnclick="fun_excel(1)" style="HEIGHT: 32px; WIDTH: 90px"> <input type="button" value="Clear Data" name="Clear" language="vbscript" οnclick="fun_excel(2)" style="HEIGHT: 32px; WIDTH: 90px"> <input type="button" value="Excel Report" name="report" language="vbscript" οnclick="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,StrRsDim 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:jobsstrCn="DRIVER={SQL Server};SERVER=server name;UID=sa;APP=Microsoft Development Environment;DATABASE=pubs;User Id=sa;PASSWORD=;"'the query string of sqlstrSQL = "Select top 8 * from jobs order by job_id"'the recordsetSet rs = df.Query(strCn, strSQL)
if t=1 then if not rs.eof thenStrRs="<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=StrRsStrRs=""elsemsgbox "No data in the table!" end ifelseif t=2 then StrRs=""adddata.innerHTML=StrRselseif t=3 then Set xlApp = CreateObject("EXCEL.APPLICATION")Set xlBook = xlApp.Workbooks.AddSet xlSheet1 = xlBook.Worksheets(1)xlSheet1.cells(1,1).value ="the job table "xlSheet1.range("A1:D1").mergexlSheet1.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 2000do 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.movenextcnt = cint(cnt) 1loopxlSheet1.Application.Visible = True
'adapt to office 2000 only'xlSheet1.Range("A3").CopyFromRecordset rs'xlSheet1.Application.Visible = Trueend if end sub</script>
转载于:https://www.cnblogs.com/cider/archive/2004/04/21/6888.html
相关资源:数据结构—成绩单生成器