大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 技术开发 -> ASP专区 -> 输出EXCEL文件的通用函数,很实用

输出EXCEL文件的通用函数,很实用

时间: 2021-07-31 作者:daque

阿余常要把形形色色的查问截止输入到excel中,以是做了底下这段小步调,用来把一个sql的select查问出的截止输入为excel方法文献,这个步调你只有设好用来博得一个记载集的sql的select查问语句和一个文献名,步调就能输入excel方法文献了,这个步调所有由三个文献形成,第一个文献的文献名为:toexcel.asp是主文献,实质如次: <% '前方是树立数据源并链接到数据库,请自行抄写关系语句,此处略过 sql=session("toexcelsql") '这边是要输入excel的查问语句,如 "sesect * form cai where 性别='女'" filename="excel.xls" ' 要输入的excel文献的文献名, 你只有改之上两句就行了,其它的都不要改. '你只有窜改之上两变量就行了.其它的我都做好了. call toexcel(filename,sql) set conn=nothing function readtext(filename) '这是一个用来读出文献的因变量 set adf=server.createobject("adodb.stream") with adf .type=2 .lineseparator=10 .open .loadfromfile (server.mappath(filename)) .charset="gb2312" .position=2 readtext=.readtext .cancel() .close() end with set ads=nothing end function sub savetext(filename,data) '这是一个用来写文献的因变量 set fs= createobject("scripting.filesystemobject") set ts=fs.createtextfile(server.mappath(filename),true) ts.writeline(data) ts.close set ts=nothing set fs=nothing end sub sub toexcel(filename,sql) '这是一个按照sql语句和filename天生excel文献 set rs=server.createobject("adodb.recordset") rs.open sql,conn,1,3 toexcellr="<table width='100%'><tr >" set myfield=rs.fields dim fieldname(50) for i=0 to myfield.count-1 toexcellr=toexcellr&"<td class=xl24>"&myfield(i).name&"</td>" fieldname(i)=myfield(i).name if myfield(i).type=135 then datename=datename&myfield(i).name&"," next toexcellr=toexcellr&"</tr>" do while not rs.eof toexcellr=toexcellr&"<tr>" for i=0 to myfield.count-1 if instr(datename,fieldname(i)&",")<>0 then if not isnull(rs(fieldname(i))) then toexcellr=toexcellr&"<td class=xl25 ><p align='left'>"&formatdatetime(rs(fieldname(i)),2)&"</p></td>" else toexcellr=toexcellr&"<td class=xl25 ><p align='left'> </p></td>" end if else toexcellr=toexcellr&"<td class=xl24 >"&rs(fieldname(i))&"</td>" end if next toexcellr=toexcellr&"</tr>" rs.movenext loop toexcellr=toexcellr&"" tou=readtext("tou.txt") di=readtext("di.txt") toexcellr=tou&toexcellr&di call savetext(filename,toexcellr) end sub %> <html> <head> <meta http-equiv="refresh" content="3;url=<%=filename%>"> <meta http-equiv="content-language" content="en-us"> <meta http-equiv="content-type" content="text/html; charset=utf8"> <title>正在天生exlce文献</title> </head> <body> 正在天生exlce文献.... </body> </html> **************第二个文献名为:di.txt 实质如次: <table x:str border=0 cellpadding=0 cellspacing=0 width=288 style='border-collapse: collapse;table-layout:fixed;width:216pt'> <![if supportmisalignedcolumns]> <tr height=0 style='display:none'> <td width=72 style='width:54pt'></td> <td width=72 style='width:54pt'></td> <td width=72 style='width:54pt'></td> <td width=72 style='width:54pt'></td> </tr> <![endif]> ************第三个文献的文献名为:tou.txt 实质如次: <html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/tr/rec-html40"> <head> <meta http-equiv=content-type content="text/html; charset=gb2312"> <meta name=progid content=excel.sheet> <meta name=generator content="microsoft excel 9"> <link rel=file-list href="./222.files/filelist.xml"> <link rel=edit-time-data href="./222.files/editdata.mso"> <link rel=ole-object-data href="./222.files/oledata.mso"> <!--[if gte mso 9]><xml> <o:documentproperties> <o:author>xky</o:author> <o:lastauthor>xky</o:lastauthor> <o:created>2002-05-27t17:51:00z</o:created> <o:lastsaved>2002-06-22t10:03:03z</o:lastsaved> <o:company>zydn</o:company> <o:version>9.2812</o:version> </o:documentproperties> <o:officedocumentsettings> <o:downloadcomponents/> <o:locationofcomponents href="file:///e:/msowc.cab"/> </o:officedocumentsettings> </xml><![endif]--> <style> <!--table {mso-displayed-decimal-separator:"\."; mso-displayed-thousand-separator:"\,";} @page {margin:1.0in .75in 1.0in .75in; mso-header-margin:.5in; mso-footer-margin:.5in;} tr {mso-height-source:auto; mso-ruby-visibility:none;} col {mso-width-source:auto; mso-ruby-visibility:none;} br {mso-data-placement:same-cell;} .style0 {mso-number-format:general; text-align:general; vertical-align:bottom; white-space:nowrap; mso-rotate:0; mso-background-source:auto; mso-pattern:auto; color:windowtext; font-size:9.0pt; font-weight:400; font-style:normal; text-decoration:none; font-family:宋体; mso-generic-font-family:auto; mso-font-charset:134; border:none; mso-protection:locked visible; mso-style-name:惯例; mso-style-id:0;} td {mso-style-parent:style0; padding-top:1px; padding-right:1px; padding-left:1px; mso-ignore:padding; color:windowtext; font-size:9.0pt; font-weight:400; font-style:normal; text-decoration:none; font-family:宋体; mso-generic-font-family:auto; mso-font-charset:134; mso-number-format:general; text-align:general; vertical-align:bottom; border:none; mso-background-source:auto; mso-pattern:auto; mso-protection:locked visible; white-space:nowrap; mso-rotate:0;} .xl24 {mso-style-parent:style0; border:.5pt solid windowtext;} .xl25 {mso-style-parent:style0; mso-number-format:"long date"; text-align:left; border:.5pt solid windowtext;} ruby {ruby-align:left;} rt {color:windowtext; font-size:9.0pt; font-weight:400; font-style:normal; text-decoration:none; font-family:宋体; mso-generic-font-family:auto; mso-font-charset:134; mso-char-type:none; display:none;} --> </style> <!--[if gte mso 9]><xml> <x:excelworkbook> <x:excelworksheets> <x:excelworksheet> <x:name>sheet1</x:name> <x:worksheetoptions> <x:defaultrowheight>225</x:defaultrowheight> <x:print> <x:validprinterinfo/> <x:papersizeindex>9</x:papersizeindex> <x:horizontalresolution>-3</x:horizontalresolution> <x:verticalresolution>0</x:verticalresolution> </x:print> <x:selected/> <x:panes> <x:pane> <x:number>3</x:number> <x:activerow>24</x:activerow> <x:activecol>5</x:activecol> </x:pane> </x:panes> <x:protectcontents>false</x:protectcontents> <x:protectobjects>false</x:protectobjects> <x:protectscenarios>false</x:protectscenarios> </x:worksheetoptions> </x:excelworksheet> <x:excelworksheet> <x:name>sheet2</x:name> <x:worksheetoptions> <x:defaultrowheight>225</x:defaultrowheight> <x:protectcontents>false</x:protectcontents> <x:protectobjects>false</x:protectobjects> <x:protectscenarios>false</x:protectscenarios> </x:worksheetoptions> </x:excelworksheet> <x:excelworksheet> <x:name>sheet3</x:name> <x:worksheetoptions> <x:defaultrowheight>225</x:defaultrowheight> <x:protectcontents>false</x:protectcontents> <x:protectobjects>false</x:protectobjects> <x:protectscenarios>false</x:protectscenarios> </x:worksheetoptions> </x:excelworksheet> </x:excelworksheets> <x:windowheight>6600</x:windowheight> <x:windowwidth>12000</x:windowwidth> <x:windowtopx>0</x:windowtopx> <x:windowtopy>1395</x:windowtopy> <x:protectstructure>false</x:protectstructure> <x:protectwindows>false</x:protectwindows> </x:excelworkbook> </xml><![endif]--> </head> <body link=blue vlink=purple>

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.