| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2459 人关注过本帖
标题:asp 查询出来的数据导出excel格式问题
只看楼主 加入收藏
hangxj
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:2045
专家分:0
注 册:2006-4-10
收藏
得分:0 
LANGUAGE="...." CODEPAGE="936...

把这句去掉

http://www./
2007-06-27 12:34
wzerolai
Rank: 1
等 级:新手上路
帖 子:52
专家分:0
注 册:2007-5-14
收藏
得分:0 

<%
dim s,sql,filename,fs,myfile,x,conn

set conn=server.CreateObject("adodb.connection")
str="provider=microsoft.jet.oledb.4.0; data source=" &server.MapPath("数据库名")
conn.open str

Set fs = server.CreateObject("scripting.filesystemobject")
'--假设你想让生成的EXCEL文件做如下的存放
filename = Server.MapPath("存放路径\orderExcel.xls") orderExcel.xls是一个固定的名字,你可以自己改
'--如果原来的EXCEL文件存在的话删除它
if fs.FileExists(filename) then
fs.DeleteFile(filename)
end if
'--创建EXCEL文件
set myfile = fs.CreateTextFile(filename,true)

Set rstData = Server.CreateObject("ADODB.Recordset")
'--从数据库中把你想放到EXCEL中的数据查出来
sql = "SQL 语句"
rstData.Open sql,conn
if not rstData.EOF and not rstData.BOF then

dim trLine,responsestr
strLine=""
For each x in rstData.fields
strLine = strLine & x.name & chr(9)
Next

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

Do while Not rstData.EOF
strLine=""

for each x in rstData.Fields
strLine = strLine & x.value & chr(9)
next
myfile.writeline strLine

rstData.MoveNext
loop

end if

rstData.Close
set rstData = nothing
Conn.Close
Set Conn = nothing
response.Redirect("存放路径\orderExcel.xls") orderExcel.xls是一个固定的名字,你可以自己改
%>

2007-06-27 13:27
xiaohonghui0
Rank: 1
等 级:新手上路
威 望:1
帖 子:274
专家分:0
注 册:2006-4-10
收藏
得分:0 
保存为excel格式:(先测试下,看我发的是不是乱码,要行一会再发个保存为word格式的)
[CODE]
<%
if request.cookies("flag")< 1 then
response.redirect "error.htm"
response.End
end if
%>
<!--#include file="conn.asp"-->
<%
Response.ContentType = "application/vnd.ms-excel"
filename="CHINACOAT_NAME"
Response.AddHeader "content-disposition", "attachment; filename=" & filename & ".xls"
%>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="90%" border="1" align="center" cellpadding="0" cellspacing="0">
<tr>
<td bgcolor="#FFFFFF"> <div align="center"><font color="#000000"><strong>Exh
name<br>
</strong></font></div></td>
<td bgcolor="#FFFFFF"> <div align="center"><font color="#000000"><strong>Co.
Name in Eng</strong></font></div></td>
<td bgcolor="#FFFFFF"> <div align="center"><font color="#000000"><strong>Co.
Name in Chinese</strong></font></div></td>
<td bgcolor="#FFFFFF"><div align="center"><strong>Chinese (Eng) Name</strong></div></td>
<%
set rs= server.CreateObject("adodb.recordset")
rs.open " select * from detail order by shortname asc",myconn,1,1
%>
<td> <div align="center"><font color="#FFFFFF"><strong><font color="#000000">Origin</font><br>
</strong></font></div></td>
<td bgcolor="#FFFFFF"> <div align="center"><font color="#000000"><strong>Origin
(Chinese)</strong></font><font color="#FFFFFF"></font></div></td>
<td bgcolor="#FFFFFF"><div align="center"><strong>Follow up office</strong></div></td>
<td bgcolor="#FFFFFF"> <div align="center"><font color="#000000"><strong>Rep
by<br>
</strong></font></div></td>
<td bgcolor="#FFFFFF"> <div align="center"><font color="#000000"><strong>NEW<br>
</strong></font></div></td>
<td bgcolor="#FFFFFF"> <div align="center"><font color="#000000"><strong>Hall</strong></font></div></td>
<td bgcolor="#FFFFFF"> <div align="center"><font color="#000000"><strong>Zone
</strong></font></div></td>
<td bgcolor="#FFFFFF"> <div align="center"><font color="#000000"><strong>Booth
No.</strong></font><font color="#FFFFFF"></font></div></td>
<td bgcolor="#FFFFFF"> <div align="center"><font color="#000000"><strong>Profile(chi)<br>
</strong></font></div></td>
<td bgcolor="#FFFFFF"> <div align="center"><font color="#000000"><strong>Profile</strong></font></div></td>
<td bgcolor="#FFFFFF"><div align="center"><strong>Add people</strong></div></td>
<td bgcolor="#FFFFFF"><div align="center"><strong>Add date</strong></div></td>
<td bgcolor="#FFFFFF"> <div align="center"><strong><font color="#000000">update
people </font></strong></div></td>
<td bgcolor="#FFFFFF"> <div align="center"><strong><font color="#000000">update
date </font></strong></div></td>
</tr>
<%do while not rs.eof%>
<tr>
<td> <div align="center"><%=rs("shortname")%></div></td>
<td><div align="center"><%=rs("companyeng")%> </div></td>
<td><%=rs("companychi")%> </td>
<td><%=rs("companychieng")%></td>
<td><div align="center"><%=rs("country")%> </div></td>
<td><%=rs("countrychi")%></td>
<td><%=rs("followup")%></td>
<td><div align="center"><%=rs("representby")%> </div></td>
<td> <div align="center"> <%=rs("new1") %> </div></td>
<td><div align="center"><%=rs("hall")%> </div></td>
<td> <div align="center"><%=rs("zone1")%></div></td>
<td> <div align="center"><%=rs("boothnumber")%></div></td>
<td> <div align="center">
<%if rs("instrchi") <>"" then response.write "Yes" end if%>
</div></td>
<td>
<%if rs("instreng") <>"" then response.write "Yes" end if%>
</td>
<td><%=rs("addman")%></td>
<td><%=year(rs("timeaddman"))&"-"&month(rs("timeaddman"))&"-"&day(rs("timeaddman"))%></td>
<td>
<%if rs("flag")>2 then%>
<%=rs("admin")%>
<%end if%>
</td>
<td>
<%if rs("flag")>2 then%>
<%=year(rs("time2"))&"-"&month(rs("time2"))&"-"&day(rs("time2"))%>
<%end if%>
</td>
</tr>
<%rs.movenext
loop
rs.close
set rs=nothing
%>
</table>[/CODE]

[此贴子已经被阳光白雪于2007-6-27 17:25:24编辑过]


曾用asp做过公司管理系统,新闻发布系统,个人网站之类,可代做网站 有意者请联系我,电话:13714123661
2007-06-27 17:20
xiaohonghui0
Rank: 1
等 级:新手上路
威 望:1
帖 子:274
专家分:0
注 册:2006-4-10
收藏
得分:0 

[CODE]<%
if request.cookies("flag")< 1 then
response.redirect "error.htm"
response.End
end if
%>
<!--#include file="conn.asp"-->
<%
Response.ContentType = "application/vnd.ms-excel"
filename="CHINACOAT_NAME"
Response.AddHeader "content-disposition", "attachment; filename=" & filename & ".xls"
%>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="90%" border="1" align="center" cellpadding="0" cellspacing="0">
<tr>
<td bgcolor="#FFFFFF"> <div align="center"><font color="#000000"><strong>Exh
name<br>
</strong></font></div></td>
<td bgcolor="#FFFFFF"> <div align="center"><font color="#000000"><strong>Co.
Name in Eng</strong></font></div></td>
<td bgcolor="#FFFFFF"> <div align="center"><font color="#000000"><strong>Co.
Name in Chinese</strong></font></div></td>
<td bgcolor="#FFFFFF"><div align="center"><strong>Chinese (Eng) Name</strong></div></td>
<%
set rs= server.CreateObject("adodb.recordset")
rs.open " select * from detail order by shortname asc",myconn,1,1
%>
<td> <div align="center"><font color="#FFFFFF"><strong><font color="#000000">Origin</font><br>
</strong></font></div></td>
<td bgcolor="#FFFFFF"> <div align="center"><font color="#000000"><strong>Origin
(Chinese)</strong></font><font color="#FFFFFF"></font></div></td>
<td bgcolor="#FFFFFF"><div align="center"><strong>Follow up office</strong></div></td>
<td bgcolor="#FFFFFF"> <div align="center"><font color="#000000"><strong>Rep
by<br>
</strong></font></div></td>
<td bgcolor="#FFFFFF"> <div align="center"><font color="#000000"><strong>NEW<br>
</strong></font></div></td>
<td bgcolor="#FFFFFF"> <div align="center"><font color="#000000"><strong>Hall</strong></font></div></td>
<td bgcolor="#FFFFFF"> <div align="center"><font color="#000000"><strong>Zone
</strong></font></div></td>
<td bgcolor="#FFFFFF"> <div align="center"><font color="#000000"><strong>Booth
No.</strong></font><font color="#FFFFFF"></font></div></td>
<td bgcolor="#FFFFFF"> <div align="center"><font color="#000000"><strong>Profile(chi)<br>
</strong></font></div></td>
<td bgcolor="#FFFFFF"> <div align="center"><font color="#000000"><strong>Profile</strong></font></div></td>
<td bgcolor="#FFFFFF"><div align="center"><strong>Add people</strong></div></td>
<td bgcolor="#FFFFFF"><div align="center"><strong>Add date</strong></div></td>
<td bgcolor="#FFFFFF"> <div align="center"><strong><font color="#000000">update
people </font></strong></div></td>
<td bgcolor="#FFFFFF"> <div align="center"><strong><font color="#000000">update
date </font></strong></div></td>
</tr>
<%do while not rs.eof%>
<tr>
<td> <div align="center"><%=rs("shortname")%></div></td>
<td><div align="center"><%=rs("companyeng")%> </div></td>
<td><%=rs("companychi")%> </td>
<td><%=rs("companychieng")%></td>
<td><div align="center"><%=rs("country")%> </div></td>
<td><%=rs("countrychi")%></td>
<td><%=rs("followup")%></td>
<td><div align="center"><%=rs("representby")%> </div></td>
<td> <div align="center"> <%=rs("new1") %> </div></td>
<td><div align="center"><%=rs("hall")%> </div></td>
<td> <div align="center"><%=rs("zone1")%></div></td>
<td> <div align="center"><%=rs("boothnumber")%></div></td>
<td> <div align="center">
<%if rs("instrchi") <>"" then response.write "Yes" end if%>
</div></td>
<td>
<%if rs("instreng") <>"" then response.write "Yes" end if%>
</td>
<td><%=rs("addman")%></td>
<td><%=year(rs("timeaddman"))&"-"&month(rs("timeaddman"))&"-"&day(rs("timeaddman"))%></td>
<td>
<%if rs("flag")>2 then%>
<%=rs("admin")%>
<%end if%>
</td>
<td>
<%if rs("flag")>2 then%>
<%=year(rs("time2"))&"-"&month(rs("time2"))&"-"&day(rs("time2"))%>
<%end if%>
</td>
</tr>
<%rs.movenext
loop
rs.close
set rs=nothing
%>
</table>[/CODE]
再试下

[此贴子已经被阳光白雪于2007-6-27 17:23:26编辑过]


曾用asp做过公司管理系统,新闻发布系统,个人网站之类,可代做网站 有意者请联系我,电话:13714123661
2007-06-27 17:22
xiaohonghui0
Rank: 1
等 级:新手上路
威 望:1
帖 子:274
专家分:0
注 册:2006-4-10
收藏
得分:0 
大家说的我都试过啊,晕,想帮忙都不好帮
13楼的帖子是复制代码到文本框,再全选代码点[IMG]http://bbs.bc-cn.net/images/post/code.gif[/IMG]
14楼的帖子是没选择LANGUAGE="...." CODEPAGE="936...,选择其他代码文字再点的
[IMG]http://bbs.bc-cn.net/images/post/code.gif[/IMG],还是不性

曾用asp做过公司管理系统,新闻发布系统,个人网站之类,可代做网站 有意者请联系我,电话:13714123661
2007-06-27 17:25
xiaohonghui0
Rank: 1
等 级:新手上路
威 望:1
帖 子:274
专家分:0
注 册:2006-4-10
收藏
得分:0 
jEpcpSX7.rar (2.72 KB) asp 查询出来的数据导出excel格式问题


算了,我还是以附件的方式发送,里面有两个文件,downselect是保存为word格式,downname是保存为excel格式的



曾用asp做过公司管理系统,新闻发布系统,个人网站之类,可代做网站 有意者请联系我,电话:13714123661
2007-06-27 17:28
阳光白雪
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:39
帖 子:2220
专家分:0
注 册:2005-11-18
收藏
得分:0 
给 你编辑过了

发帖的时候把


图片附件: 游客没有浏览图片的权限,请 登录注册



这个去掉就可以了

专注于WEB前端交互平台开发:[url=http://blog./]blog.[/url](富客户端技术(RIA)交流平台)
2007-06-27 17:28
xiaohonghui0
Rank: 1
等 级:新手上路
威 望:1
帖 子:274
专家分:0
注 册:2006-4-10
收藏
得分:0 
我发送的代码怎么都显示正常了,是不是斑主帮我弄了下?

曾用asp做过公司管理系统,新闻发布系统,个人网站之类,可代做网站 有意者请联系我,电话:13714123661
2007-06-27 17:29
xiaohonghui0
Rank: 1
等 级:新手上路
威 望:1
帖 子:274
专家分:0
注 册:2006-4-10
收藏
得分:0 
哦,谢谢你
急死我了,想帮忙都没办法,呵呵

曾用asp做过公司管理系统,新闻发布系统,个人网站之类,可代做网站 有意者请联系我,电话:13714123661
2007-06-27 17:30
yms123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:209
帖 子:12488
专家分:19042
注 册:2004-7-17
收藏
得分:0 
http://www.aspxuexi.com/sql/excel/2006-10-12/1280.htm
个人所知ADODB可以把数据写入Excel工作表内。
2007-06-27 20:40
快速回复:asp 查询出来的数据导出excel格式问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013575 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved