?? 如何用asp把sql server數據轉化為execl文件 .htm
字號:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0054)http://www.51base.com/article/view_article.asp?id=1875 -->
<HTML lang=zh-cn><HEAD><TITLE>NB聯盟</TITLE>
<META content="text/html; charset=gb2312" http-equiv=Content-Type><LINK
href="NB聯盟2.files/style.css" rel=stylesheet>
<META content="MSHTML 5.00.2614.3500" name=GENERATOR></HEAD>
<BODY><!-- start page body -->
<TABLE align=center border=0 cellPadding=0 cellSpacing=0 class=td id=position
width=773>
<TBODY>
<TR>
<TD class=shadow colSpan=2 height=20 width=262> <A
href="http://www.51base.com/"><IMG border=0
src="NB聯盟2.files/logo1.gif"></A> </TD>
<TD align=right width=505>
<P align=left></P></TD></TR></TBODY></TABLE>
<TABLE align=center border=0 cellPadding=0 cellSpacing=0 id=main width=770>
<TBODY>
<TR>
<TD class=tdlbr vAlign=top>
<TABLE align=center border=0 cellPadding=0 cellSpacing=0 id=welcome
style="TABLE-LAYOUT: fixed" width="98%">
<TBODY>
<TR>
<TD style="TABLE-LAYOUT: fixed; WORD-BREAK: break-all"
vAlign=top><FONT color=red><B>文章標題</B></FONT><FONT color=red><B>:
如何用asp把sql server數據轉化為execl文件 </B></FONT>
<HR noShade SIZE=1>
<SPAN class=content id=BodyLabel
style="DISPLAY: block; PADDING-BOTTOM: 0px; PADDING-LEFT: 10px; PADDING-RIGHT: 10px; PADDING-TOP: 0px">1、ASP文件:
<P></P>
<P><%@ LANGUAGE="VBSCRIPT" %><BR><%option
explicit%><BR><%<BR>'EXAMPLE
AS:把數據庫中一個每天24小時在線人數放到一個EXCEL文件中去<BR>'AUTHOR :鋼鐵工人<BR>'EMAIL
:hello_hhb@21cn.com<BR>'DATE :2001-3-25<BR>'TEST :在NT4,SP6,SQL
SERVER
7.0,EXCEL2000中測試通過<BR>%><BR><HTML><BR><HEAD><BR><meta
content="text/html; charset=gb2312"
http-equiv="Content-Type"><BR><TITLE>生成EXCEL文件</TITLE><BR></HEAD><BR><body><BR><a
href="dbtoexcel.asp?act=make">生成在線人口的EXCEL</a><BR><hr
size=1 align=left width=300px><BR><%<BR>if Request("act") = ""
then<BR>else</P>
<P>dim conn<BR>set
conn=server.CreateObject("adodb.connection")<BR>conn.Open
"test","sa",""<BR>'conn.Open Application("connstr")</P>
<P>dim rs,sql,filename,fs,myfile,x,link<BR><BR>Set fs =
server.CreateObject("scripting.filesystemobject")<BR>'--假設你想讓生成的EXCEL文件做如下的存放<BR>filename
= "c:\online.xls"<BR>'--如果原來的EXCEL文件存在的話刪除它<BR>if
fs.FileExists(filename) then<BR>fs.DeleteFile(filename)<BR>end
if<BR>'--創建EXCEL文件<BR>set myfile =
fs.CreateTextFile(filename,true)</P>
<P><BR><BR>Set rs =
Server.CreateObject("ADODB.Recordset")<BR>'--從數據庫中把你想放到EXCEL中的數據查出來<BR>sql
= "select population,hourpos,datepos from populationperhour order by
datepos,hourpos asc"<BR>rs.Open sql,conn<BR>if rs.EOF and rs.BOF
then<BR><BR>else<BR><BR>dim strLine,responsestr<BR>strLine=""<BR>For
each x in rs.fields<BR>strLine= strLine & x.name &
chr(9)<BR>Next<BR><BR>'--將表的列名先寫入EXCEL<BR>myfile.writeline
strLine</P>
<P>Do while Not rs.EOF<BR>strLine=""<BR><BR>for each x in
rs.Fields<BR>strLine= strLine & x.value &
chr(9)<BR>next<BR>'--將表的數據寫入EXCEL<BR>myfile.writeline strLine</P>
<P>rs.MoveNext<BR>loop<BR><BR>end if</P>
<P>rs.Close<BR>set rs = nothing<BR>conn.close<BR>set conn =
nothing<BR>set myfile = nothing<BR>Set fs=Nothing</P>
<P>link="<A HREF=" & filename & ">Open The Excel
File</a>"<BR>Response.write link<BR>end
if<BR>%><BR></BODY><BR></HTML></P>
<P><BR>2、數據庫相關:</P>
<P>CREATE TABLE [populationperhour] (<BR>[population] [int] NOT NULL
,<BR>[hourpos] [int] NOT NULL ,<BR>[datepos] [datetime] NOT NULL
<BR>);<BR>insert into populationperhour
values('936','1','2001-1-11');<BR>insert into populationperhour
values('636','2','2001-1-11');<BR>insert into populationperhour
values('106','3','2001-1-11');<BR>insert into populationperhour
values('177','4','2001-1-11');<BR>insert into populationperhour
values('140','5','2001-1-11');<BR>insert into populationperhour
values('114','6','2001-1-11');<BR>insert into populationperhour
values('94','7','2001-1-11');<BR>insert into populationperhour
values('49','8','2001-1-11');<BR>insert into populationperhour
values('88','9','2001-1-11');<BR>insert into populationperhour
values('215','10','2001-1-11');<BR>insert into populationperhour
values('370','11','2001-1-11');<BR>insert into populationperhour
values('550','12','2001-1-11');<BR>insert into populationperhour
values('629','13','2001-1-11');<BR>insert into populationperhour
values('756','14','2001-1-11');<BR>insert into populationperhour
values('833','15','2001-1-11');<BR>insert into populationperhour
values('923','16','2001-1-11');<BR>insert into populationperhour
values('980','17','2001-1-11');<BR>insert into populationperhour
values('957','18','2001-1-11');<BR>insert into populationperhour
values('812','19','2001-1-11');<BR>insert into populationperhour
values('952','20','2001-1-11');<BR>insert into populationperhour
values('1379','21','2001-1-11');<BR>insert into populationperhour
values('1516','22','2001-1-11');<BR>insert into populationperhour
values('1476','23','2001-1-11');<BR>insert into populationperhour
values('1291','24','2001-1-11');<BR>insert into populationperhour
values('1028','1','2001-1-12');<BR>insert into populationperhour
values('687','2','2001-1-12');<BR>insert into populationperhour
values('462','3','2001-1-12');<BR>insert into populationperhour
values('317','4','2001-1-12');<BR>insert into populationperhour
values('221','5','2001-1-12');<BR>insert into populationperhour
values('158','6','2001-1-12');<BR>insert into populationperhour
values('127','7','2001-1-12');<BR>insert into populationperhour
values('81','8','2001-1-12');<BR>insert into populationperhour
values('96','9','2001-1-12');<BR>insert into populationperhour
values('192','10','2001-1-12');<BR>insert into populationperhour
values('380','11','2001-1-12');<BR>insert into populationperhour
values('629','12','2001-1-12');<BR>insert into populationperhour
values('745','13','2001-1-12');<BR>insert into populationperhour
values('964','14','2001-1-12');<BR>insert into populationperhour
values('1012','15','2001-1-12');<BR>insert into populationperhour
values('1050','16','2001-1-12');<BR>insert into populationperhour
values('1135','17','2001-1-12');<BR>insert into populationperhour
values('1130','18','2001-1-12');<BR>insert into populationperhour
values('894','19','2001-1-12');<BR>insert into populationperhour
values('1026','20','2001-1-12');<BR>insert into populationperhour
values('1430','21','2001-1-12');<BR>insert into populationperhour
values('1777','22','2001-1-12');<BR>insert into populationperhour
values('1759','23','2001-1-12');<BR>insert into populationperhour
values('1697','24','2001-1-12');<BR><
</P></SPAN></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR>
<TABLE align=center border=0 cellPadding=2 cellSpacing=0 id=footer width=770>
<TBODY>
<TR>
<TD align=middle class=tdt>
<P align=center></P></TD></TR></TBODY></TABLE><BR></BODY></HTML>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -