asp如何将数据库中内容生成为excell文件

iamchristina 2003-12-23 09:35:25
要求客户端能够得到该excell文件

谢谢各位
...全文
35 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
one_wang 2003-12-23
  • 打赏
  • 举报
回复
不一定是excell文件,其实csv文件可以另存为xls文件

注:csv文件时间逗号分隔的文件.
13968 2003-12-23
  • 打赏
  • 举报
回复
如果是规则的生成一条条纪录的话,可以很容易实现,但如果要生成不规则的纪录就比较麻烦了,我现在正在找这方面的资料
yzwxjun 2003-12-23
  • 打赏
  • 举报
回复
<%@ LANGUAGE="VBSCRIPT" %>
<%option explicit%>
<HTML>
<HEAD>
<meta content="text/html; charset=gb2312" http-equiv="Content-Type">
<TITLE>生成EXCEL文件</TITLE>
</HEAD>
<body>
<a href="1011.asp?act=make">生成在线人口的EXCEL</a>
<hr size=1 align=left width=300px>
<%
if Request("act") = "" then
Response.Write "生成EXCEL文件"
else

dim conn,strconn
strconn="driver={SQL Server};server=你的服务器;uid=用户名;pwd=密码;database=数据库"
set conn=server.CreateObject("adodb.connection")
conn.Open strconn

dim rs,sql,filename,fs,myfile,x

Set fs = server.CreateObject("scripting.filesystemobject")
'--假设你想让生成的EXCEL文件做如下的存放
filename = Server.MapPath("online.xls")
'--如果原来的EXCEL文件存在的话删除它
if fs.FileExists(filename) then
fs.DeleteFile(filename)
end if
'--创建EXCEL文件
set myfile = fs.CreateTextFile(filename,true)

Set rs = Server.CreateObject("ADODB.Recordset")
'--从数据库中把你想放到EXCEL中的数据查出来
sql = "select * from new order by id desc"
rs.Open sql,conn
if rs.EOF and rs.BOF then
Response.Write "库里暂时没有数据!"
else
dim strLine,responsestr
strLine=""
For each x in rs.fields
strLine= strLine & x.name & chr(9)
Next

'--将表的列名先写入EXCEL
myfile.writeline strLine

Do while Not rs.EOF
strLine=""

for each x in rs.Fields
strLine= strLine & x.value & chr(9)
next
'--将表的数据写入EXCEL
myfile.writeline strLine

rs.MoveNext
loop
end if
rs.Close
set rs = nothing
conn.close
set conn = nothing
set myfile = nothing
Set fs=Nothing
end if
%>
</BODY>
</HTML>
jumpnew929 2003-12-23
  • 打赏
  • 举报
回复
用VBA吧
不过以前我用过一个土办法,就是把HTML文件扩展名改XLS也可以

28,407

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧