您尚未登录,请登录后浏览更多内容! 登录 | 立即注册

QQ登录

只需一步,快速开始

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1931|回复: 0

客户端用ASP+rds+VBA参生报表(高级篇)

[复制链接]

20

主题

0

听众

26

积分

应届毕业生

Rank: 1

性别
保密
听众数
0
买家信用
卖家信用
在线时间
0 小时
相册
0
发表于 2006-8-8 14:08:00 |显示全部楼层
程序员装备

客户端用ASP+rds+VBA参生报表(高级篇)<br><br>test_print_report.asp <br><br>&lt;html&gt; <br>&lt;head&gt; <br>&lt;meta content=&quot;text/html; charset=BIG5&quot; http-equiv=&quot;Content-Type&quot;&gt; <br>&lt;title&gt;client use rds produce excel report&lt;/title&gt; <br>&lt;/head&gt; <br>&lt;body bgColor=&quot;skyblue&quot; topMargin=0 leftMargin=&quot;20&quot; oncontextmenu=&quot;return false&quot; rightMargin=&quot;0&quot; bottomMargin=&quot;0&quot;&gt; <br>&lt;form action=&quot;test_print_report.asp&quot; method=&quot;post&quot; name=&quot;myform&quot;&gt; <br>&lt;div align=&quot;center&quot;&gt;&lt;center&gt; <br>&lt;table border=&quot;5&quot; bgcolor=&quot;#ffe4b5&quot; style=&quot;HEIGHT: 1px; TOP: 0px&quot; bordercolor=&quot;#0000ff&quot;&gt; <br>&lt;tr&gt; <br>&lt;td align=&quot;middle&quot; bgcolor=&quot;#ffffff&quot; bordercolor=&quot;#000080&quot;&gt; <br>&lt;font color=&quot;#000080&quot; size=&quot;3&quot;&gt; <br>client use rds produce excel report <br>&lt;/font&gt; <br>&lt;/td&gt; <br>&lt;/tr&gt; <br>&lt;/table&gt; <br>&lt;/div&gt; <br>&lt;div align=&quot;left&quot;&gt; <br>&lt;input type=&quot;button&quot; value=&quot;Query Data&quot; name=&quot;query&quot; language=&quot;vbscrip..&quot; onclick=&quot;fun_query()&quot; style=&quot;HEIGHT: 32px; WIDTH: 90px&quot;&gt; <br>&lt;input type=&quot;button&quot; value=&quot;Clear Data&quot; name=&quot;Clear&quot; language=&quot;vbscrip..&quot; onclick=&quot;fun_clear()&quot; style=&quot;HEIGHT: 32px; WIDTH: 90px&quot;&gt; <br>&lt;input type=&quot;button&quot; value=&quot;Excel Report&quot; name=&quot;report&quot; language=&quot;vbscrip..&quot; onclick=&quot;fun_excel()&quot; style=&quot;HEIGHT: 32px; WIDTH: 90px&quot;&gt; <br>&lt;/div&gt; <br>&lt;div id=&quot;adddata&quot;&gt;&lt;/div&gt; <br>&lt;/form&gt;&lt;/center&gt; <br>&lt;/body&gt; <br>&lt;/html&gt; <br>&lt;scrip.. language=&quot;vbscrip..&quot;&gt; <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(&quot;RDS.DataSpace&quot;) <br>Set df = rds.CreateObject(&quot;RDSServer.DataFactory&quot;,&quot;http://iscs00074&quot;) <br>strCn=&quot;DRIVER={SQL Server};SERVER=iscs00074;UID=sa;APP=Microsoft Development Environment;DATABASE=pubs;User Id=sa;PASSWORD=;&quot; <br>strSQL = &quot;Select * from jobs&quot; <br>Set rs = df.Query(strCn, strSQL) <br><br>if not rs.eof then <br>StrRs=&quot;&lt;table border=1&gt;&lt;tr&gt;&lt;td&gt;job_id&lt;/td&gt;&lt;td&gt;job_desc&lt;/td&gt;&lt;td&gt;max_lvl&lt;/td&gt;&lt;td&gt;min_lvl&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&quot;+ rs.GetString(,,&quot;&lt;/td&gt;&lt;td&gt;&quot;,&quot;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&quot;,&quot; &quot;) +&quot;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&quot; <br>adddata.innerHTML=StrRs <br>StrRs=&quot;&quot; <br>else <br>msgbo.. &quot;No data in the table!&quot; <br>end if <br>end sub <br><br>sub fun_clear() <br>StrRs=&quot;&quot; <br>adddata.innerHTML=StrRs <br>end sub <br><br>sub fun_excel() <br>set rds = CreateObject(&quot;RDS.DataSpace&quot;) <br>Set df = rds.CreateObject(&quot;RDSServer.DataFactory&quot;,&quot;http://iscs00074&quot;) <br>strCn=&quot;DRIVER={SQL Server};SERVER=iscs00074;UID=sa;APP=Microsoft Development Environment;DATABASE=pubs;User Id=sa;PASSWORD=;&quot; <br>strSQL = &quot;Select count(*) as recordcnt from jobs&quot; <br>Set rs = df.Query(strCn, strSQL) <br>TotalPageCnt=rs(&quot;recordcnt&quot;) <br>rs.close <br>set rs=nothing <br>strSQL = &quot;Select * from jobs&quot; <br>Set rs = df.Query(strCn, strSQL) <br>Set xlApp = CreateObject(&quot;EXCEL.APPLICATION&quot;) <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&lt;= HeadRowCnt <br>With xlSheet1 <br>.range(&quot;C&quot;+trim(RowCnt)+&quot;:&quot;+&quot;D&quot;+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 = &quot;THE JOB INFORMATION TABLE&quot; <br>.Cells(RowCnt-3, 3).Value = date() <br>.Cells(RowCnt-4, 3).Value = &quot;The &quot;+trim(PageNo)+&quot;/&quot;+trim(TotalPageCnt) +&quot; Pages&quot; <br>end with <br>@#Format the title field name of cells <br>With xlSheet1 <br>.range(&quot;A&quot;+trim(RowCnt) +&quot;:B&quot;+trim(RowCnt)).merge <br>.range(&quot;A&quot;+trim(RowCnt+1) +&quot;:A&quot;+trim(RowCnt+2)).merge <br>.range(&quot;B&quot;+trim(RowCnt+1) +&quot;:B&quot;+trim(RowCnt+2)).merge <br><br>.range(&quot;C&quot;+trim(RowCnt) +&quot;:D&quot;+trim(RowCnt)).merge <br>.range(&quot;C&quot;+trim(RowCnt+1) +&quot;:C&quot;+trim(RowCnt+2)).merge <br>.range(&quot;D&quot;+trim(RowCnt+1) +&quot;:D&quot;+trim(RowCnt+2)).merge <br><br>.Cells(RowCnt, 1).Value = &quot;The job&quot; <br>.Cells(RowCnt+1,1).Value = &quot;job_id&quot; <br>.Cells(RowCnt+1,2).Value = &quot;job_desc&quot; <br>.Cells(RowCnt, 3).Value = &quot;Level&quot; <br>.Cells(RowCnt+1,3).Value = &quot;Max level&quot; <br>.Cells(RowCnt+1,4).Value = &quot;Min level&quot; <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&lt;= FootRowCnt <br>With xlSheet1 <br>.range(&quot;C&quot;+trim(RowCnt)+&quot;:&quot;+&quot;D&quot;+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 = &quot;A:&quot; <br>.Cells(RowCnt-1, 2).Value = &quot;B:&quot; <br>.Cells(RowCnt-1, 3).Value = &quot;C:&quot; <br>end with <br>end sub <br><br>sub format_grid() <br>dim strCode <br>dim MyMacro <br>strCode = _ <br>&quot;sub MyMacro() &quot; &amp; vbCr &amp; _ <br>&quot;dim HeadRowCnt&quot; &amp; vbCr &amp; _ <br>&quot;dim TitleRowCnt&quot; &amp; vbCr &amp; _ <br>&quot;dim ContentRowCnt&quot; &amp; vbCr &amp; _ <br>&quot;dim FootRowCnt&quot; &amp; vbCr &amp; _ <br>&quot;dim PageRowCnt&quot; &amp; vbCr &amp; _ <br>&quot;dim BgnCnt&quot; &amp; vbCr &amp; _ <br>&quot;HeadRowCnt=&quot;&amp; HeadRowCnt &amp;&quot;&quot; &amp; vbCr &amp; _
您需要登录后才可以回帖 登录 | 立即注册


关闭

站长推荐上一条 /1 下一条



      
    Archiver|手机版|臣迅电子商务|网站地图|渝ICP备11003388号

GMT+8, 2012-5-20 09:05

© 2001-2011 Powered by Discuz! X2.5. Theme By Yeei! update By CNNTEC

webSite begin 2005

回顶部