📄 asp往excel导数据问题.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0055)http://www.51base.com/article/view_article.asp?id=79693 -->
<HTML lang=zh-cn><HEAD><TITLE>NB联盟</TITLE>
<META content="text/html; charset=gb2312" http-equiv=Content-Type><LINK
href="NB联盟36.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联盟36.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往EXCEL导数据问题? </B></FONT>
<HR noShade SIZE=1>
<BR>见帖
http://expert.csdn.net/Expert/topic/1969/1969510.xml?temp=.4360163
<BR>---------------------------------------------------------------
<BR> <BR>'确保文件名唯一 <BR>strFileName =
Session.SessionID & ".xls"
<BR>strAppPath =
Request.ServerVariables("PATH_TRANSLATED")
<BR>strAppPath = Left(strAppPath,
InstrRev(strAppPath, "\")) <BR>strFullPath =
strAppPath & strFileName <BR>'保存文件
<BR>myWorkbook.SaveAs(strFullPath) <BR>'关闭Excel
<BR>myWorkbook.Close <BR>xlApp.Quit <BR>set
myWorksheet = Nothing <BR>set
myWorkbook = Nothing <BR>set myxlApp
= Nothing <BR>'写出到浏览器中 <BR>Response.Redirect
strFileName
<BR> <BR>---------------------------------------------------------------
<BR> <BR><%@ LANGUAGE="VBSCRIPT" %>
<BR><%option explicit%> <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> Response.Write
"生成EXCEL文件" <BR>else <BR> <BR>dim
conn,strconn <BR>strconn="driver={SQL
Server};server=wen;uid=sa;pwd=;database=DB_Test" <BR>set
conn=server.CreateObject("adodb.connection")
<BR>conn.Open strconn <BR> <BR>dim
rs,sql,filename,fs,myfile,x <BR> <BR>Set fs
= server.CreateObject("scripting.filesystemobject")
<BR>'--假设你想让生成的EXCEL文件做如下的存放 <BR>filename =
Server.MapPath("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) <BR> <BR>Set
rs = Server.CreateObject("ADODB.Recordset")
<BR>'--从数据库中把你想放到EXCEL中的数据查出来 <BR>sql =
"select * from Tb_Execl order by
sort desc" <BR>rs.Open sql,conn <BR>if
rs.EOF and rs.BOF then <BR>
Response.Write "库里暂时没有数据!" <BR>else
<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 <BR> <BR>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
<BR> <BR>rs.MoveNext <BR>loop <BR>end
if <BR>rs.Close <BR>set rs =
nothing <BR>conn.close <BR>set conn =
nothing <BR>set myfile = nothing
<BR>Set fs=Nothing <BR>end if
<BR>%> <BR></BODY> <BR></HTML>
<BR><BR></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 + -