asp从access导出为csv文件



<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>export</title>
</head>
<!--#include file="../Include/Const.asp" -->
<!--#include file="../Include/ConnSiteData.asp" -->
<body>

<%
'设置页面时间
Server.ScriptTimeOut=999999
dim s,sql,filename,fs,myfile,x,mFileName,ObjExcel,ObjSheet
Set fs = server.CreateObject("scripting.filesystemobject")
filename = Server.MapPath("contact.csv")

'--如果原来的EXCEL文件存在的话删除它
if fs.FileExists(filename) then
fs.DeleteFile(filename)
end if
'--创建csv文件
set myfile = fs.CreateTextFile(filename,true)

'--从数据库中把你想放到csv中的数据查出来
strSql = "select * from Ameav_Contact order by OrgName asc"
'--显示执行的SQL语句
Response.Write "<div id='sql'><strong>SQL 语句:</strong><br />"&strSql&"</div>"
Set Rs =conn.execute(strSql)
if not Rs.EOF and not Rs.BOF then
dim trLine,responsestr
strLine=""
For each x in Rs.fields
strLine = "OrgName,DepName,StaffName,Office,SubPhone,DirecPhone,Telephone,PersonEmail,CompanyEmail,Password,Remark"'Public,Password,Remark"
Next

myfile.writeline strLine
Response.Write "<div id='data'>"
Do while Not Rs.EOF
strLine=""
strLine= Rs("OrgName")&"," & Rs("DepName")&"," & Rs("StaffName") & "," & Rs("Office") & "," & Rs("SubPhone") & "," & Rs("DirecPhone") & "," & Rs("Telephone") & "," & Rs("PersonEmail") & "," & Rs("CompanyEmail") & "," & Rs("Password") & "," & Rs("Remark")'& Rs("Public") & "," & Rs("Password") & "," & Rs("Remark")
if WriteDB=True then
Response.Write strLine & "<br /><hr />"
end if
myfile.writeline strLine
Rs.MoveNext
loop
Response.Write "</div>"
end if

Response.Write "<div id='down'><p><a href=""contact.csv"" target=""_blank"">生成文件成功,点击下载!</a></p></div>"
Rs.Close :set Rs = nothing
Conn.Close:Set Conn = nothing
%>


</body>
</html>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值