- 注册时间
- 2006-7-3
- 最后登录
- 2007-1-20
- 阅读权限
- 10
- 积分
- 26
- 精华
- 0
- 帖子
- 26

- 性别
- 保密
- 听众数
- 0
- 买家信用
 - 卖家信用
 - 在线时间
- 0 小时
- 相册
- 0
|
|
客户端用ASP+rds+VBA参生报表(高级篇)<br><br>test_print_report.asp <br><br><html> <br><head> <br><meta content="text/html; charset=BIG5" http-equiv="Content-Type"> <br><title>client use rds produce excel report</title> <br></head> <br><body bgColor="skyblue" topMargin=0 leftMargin="20" oncontextmenu="return false" rightMargin="0" bottomMargin="0"> <br><form action="test_print_report.asp" method="post" name="myform"> <br><div align="center"><center> <br><table border="5" bgcolor="#ffe4b5" style="HEIGHT: 1px; TOP: 0px" bordercolor="#0000ff"> <br><tr> <br><td align="middle" bgcolor="#ffffff" bordercolor="#000080"> <br><font color="#000080" size="3"> <br>client use rds produce excel report <br></font> <br></td> <br></tr> <br></table> <br></div> <br><div align="left"> <br><input type="button" value="Query Data" name="query" language="vbscrip.." onclick="fun_query()" style="HEIGHT: 32px; WIDTH: 90px"> <br><input type="button" value="Clear Data" name="Clear" language="vbscrip.." onclick="fun_clear()" style="HEIGHT: 32px; WIDTH: 90px"> <br><input type="button" value="Excel Report" name="report" language="vbscrip.." onclick="fun_excel()" style="HEIGHT: 32px; WIDTH: 90px"> <br></div> <br><div id="adddata"></div> <br></form></center> <br></body> <br></html> <br><scrip.. language="vbscrip.."> <br>dim rds,rs,df <br>dim strsql,StrRs,strCn,RowCnt <br>dim xlApp, xlBook, xlSheet1,xlmodule,XlPageSetup <br>dim HeadRowCnt,TitleRowCnt,ContentRowCnt,FootRowCnt <br>dim PageRowCnt,PageNo,TotalPageCnt,ContentRowNowCnt <br>dim ColumnAllWidth,ColumnAWidth,ColumnBWidth,ColumnCWidth,ColumnDWidth <br><br>sub fun_query() <br>set rds = CreateObject("RDS.DataSpace") <br>Set df = rds.CreateObject("RDSServer.DataFactory","http://iscs00074") <br>strCn="DRIVER={SQL Server};SERVER=iscs00074;UID=sa;APP=Microsoft Development Environment;DATABASE=pubs;User Id=sa;PASSWORD=;" <br>strSQL = "Select * from jobs" <br>Set rs = df.Query(strCn, strSQL) <br><br>if not rs.eof then <br>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>" <br>adddata.innerHTML=StrRs <br>StrRs="" <br>else <br>msgbo.. "No data in the table!" <br>end if <br>end sub <br><br>sub fun_clear() <br>StrRs="" <br>adddata.innerHTML=StrRs <br>end sub <br><br>sub fun_excel() <br>set rds = CreateObject("RDS.DataSpace") <br>Set df = rds.CreateObject("RDSServer.DataFactory","http://iscs00074") <br>strCn="DRIVER={SQL Server};SERVER=iscs00074;UID=sa;APP=Microsoft Development Environment;DATABASE=pubs;User Id=sa;PASSWORD=;" <br>strSQL = "Select count(*) as recordcnt from jobs" <br>Set rs = df.Query(strCn, strSQL) <br>TotalPageCnt=rs("recordcnt") <br>rs.close <br>set rs=nothing <br>strSQL = "Select * from jobs" <br>Set rs = df.Query(strCn, strSQL) <br>Set xlApp = CreateObject("EXCEL.APPLICATION") <br>Set xlBook = xlApp.Workbooks.Add <br>Set xlSheet1 = xlBook.ActiveSheet <br>Set xlmodule = xlbook.VBProject.VBComponents.Add(1) <br>xlSheet1.Application.Visible = True <br>xlSheet1.Application.UserControl = True <br>i=0 <br>RowCnt=1 <br>PageNo=1 <br>HeadRowCnt=4 @#The header number to print in one page! <br>TitleRowCnt=3 @#The title number to print in one page! <br>ContentRowCnt=6 @#The record number to print in one page! <br>FootRowCnt=1 @#The footer number to print in one page! <br>PageRowCnt=HeadRowCnt+TitleRowCnt+ContentRowCnt+FootRowCnt <br>TotalPageCnt=int((TotalPageCnt+ContentRowCnt-1)/ContentRowCnt) <br>ColumnAWidth=5 @#The ColumnA Width! <br>ColumnBWidth=30 @#The ColumnB Width! <br>ColumnCWidth=5 @#The ColumnC Width! <br>ColumnDWidth=5 @#The ColumnD Width! <br>@#Add the Head and Title <br>call head_title <br>@#Add the Data <br>do while not rs.eof <br>With xlSheet1 <br>.cells(RowCnt,1).value = rs(0) <br>.cells(RowCnt,2).value = rs(1) <br>.cells(RowCnt,3).value = rs(2) <br>.cells(RowCnt,4).value = rs(3) <br>end with <br>rs.movenext <br>ContentRowNowCnt=ContentRowNowCnt+1 <br>if not rs.eof then <br>if ContentRowNowCnt mod (ContentRowCnt) =0 then <br>ContentRowNowCnt=0 <br>RowCnt = cint(RowCnt) + 1 <br>@#Add the Foot <br>call foot_title <br>@#Add the Head and Title <br>call head_title <br>else <br>RowCnt = cint(RowCnt) + 1 <br>end if <br>else <br>RowCnt = cint(RowCnt) + 1 <br>call foot_title <br>end if <br>loop <br>@#Format the Grid and Font <br>call format_grid <br>@#Release References <br>@#XLSheet1.PrintOut <br>@#xlBook.Saved = True <br>Set xlmodule = Nothing <br>Set xlSheet1 = Nothing <br>Set xlBook = Nothing <br>xlApp.Quit <br>Set xlApp = Nothing <br>rs.close <br>set rs=nothing <br>end sub <br><br><br>sub head_title() <br>dim HeadRow <br>HeadRow=1 <br>do while HeadRow<= HeadRowCnt <br>With xlSheet1 <br>.range("C"+trim(RowCnt)+":"+"D"+trim(RowCnt)).merge <br>end with <br>RowCnt=RowCnt+1 <br>HeadRow=HeadRow+1 <br>loop <br><br>@#Format the head name of cells (The new page of row=5,6,7) <br><br>With xlSheet1 <br>.Cells(RowCnt-3, 2).Value = "THE JOB INFORMATION TABLE" <br>.Cells(RowCnt-3, 3).Value = date() <br>.Cells(RowCnt-4, 3).Value = "The "+trim(PageNo)+"/"+trim(TotalPageCnt) +" Pages" <br>end with <br>@#Format the title field name of cells <br>With xlSheet1 <br>.range("A"+trim(RowCnt) +":B"+trim(RowCnt)).merge <br>.range("A"+trim(RowCnt+1) +":A"+trim(RowCnt+2)).merge <br>.range("B"+trim(RowCnt+1) +":B"+trim(RowCnt+2)).merge <br><br>.range("C"+trim(RowCnt) +":D"+trim(RowCnt)).merge <br>.range("C"+trim(RowCnt+1) +":C"+trim(RowCnt+2)).merge <br>.range("D"+trim(RowCnt+1) +":D"+trim(RowCnt+2)).merge <br><br>.Cells(RowCnt, 1).Value = "The job" <br>.Cells(RowCnt+1,1).Value = "job_id" <br>.Cells(RowCnt+1,2).Value = "job_desc" <br>.Cells(RowCnt, 3).Value = "Level" <br>.Cells(RowCnt+1,3).Value = "Max level" <br>.Cells(RowCnt+1,4).Value = "Min level" <br>End With <br>RowCnt=int(RowCnt)+3 <br>PageNo=PageNo+1 <br>end sub <br><br>sub foot_title() <br>dim FootRow <br>FootRow=1 <br>do while FootRow<= FootRowCnt <br>With xlSheet1 <br>.range("C"+trim(RowCnt)+":"+"D"+trim(RowCnt)).merge <br>end with <br>RowCnt=RowCnt+1 <br>FootRow=FootRow+1 <br>loop <br>With xlSheet1 <br>.Cells(RowCnt-1, 1).Value = "A:" <br>.Cells(RowCnt-1, 2).Value = "B:" <br>.Cells(RowCnt-1, 3).Value = "C:" <br>end with <br>end sub <br><br>sub format_grid() <br>dim strCode <br>dim MyMacro <br>strCode = _ <br>"sub MyMacro() " & vbCr & _ <br>"dim HeadRowCnt" & vbCr & _ <br>"dim TitleRowCnt" & vbCr & _ <br>"dim ContentRowCnt" & vbCr & _ <br>"dim FootRowCnt" & vbCr & _ <br>"dim PageRowCnt" & vbCr & _ <br>"dim BgnCnt" & vbCr & _ <br>"HeadRowCnt="& HeadRowCnt &"" & vbCr & _ |
|