您的位置:首页 > 编程语言 > ASP

ASP动态生成CSV文件

2008-12-02 10:36 295 查看
<% '生成文件名流水号
birth = formatdatetime(now,2)
enyear = CStr(year(birth))
enmonth = month(birth)
enday = day(birth)
if len(CInt(enmonth))=1 then
enmonth="0"&CStr(enmonth)
end if
if len(CInt(enday))=1 then
enday="0"&CStr(enday)
end if
birth_no=enyear&enmonth&enday

birth2 = formatdatetime(now,3)
enhour = hour(birth2)
enminute = minute(birth2)
ensecond = second(birth2)
if len(CInt(enhour))=1 then
enhour="0"&CStr(enhour)
end if
if len(CInt(enminute))=1 then
enminute="0"&CStr(enminute)
end if
if len(CInt( ensecond))=1 then
ensecond="0"&CStr( ensecond)
end if
birth_no=enyear&enmonth&enday&enhour&enminute&ensecond

%>
<% Response.Buffer = true
Response.AddHeader "Content-Disposition","attachment; filename=文件名_"&birth_no&".csv"
Response.CharSet = "iso-8859-1" '文件编码
Response.ContentType = "application/octet-stream" %>

<!--#include file="conn.asp"-->

<%
set rs = conn.Execute("SELECT * FROM TABLES")
Response.Write rs.fields(0).name
for i=1 to rs.fields.count-1
Response.Write ";" & rs.fields(i).name
next
Response.Flush()

do while not rs.eof
Response.Write vbCrLf & rs(0)
for i=1 to rs.fields.count-1
Response.Write ";" & rs(i)
next
Response.Flush()
rs.Movenext

loop
rs.Close
conn.Close
set rs = nothing
set conn = nothing
Response.End()
%>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  asp 职场 休闲 csv