经典ASP导出到CSV会生成第1行空白

时间:2014-11-06 22:25:46

标签: csv asp-classic export-to-csv

我有一个.asp页面,它使用mysql数据库中的数据生成要下载的csv文件。我的问题是,生成的csv文件的第一行是空白的。如何消除输出中的空白第1行?

<%Response.Buffer = True
Response.Clear
Response.ContentType = "text/csv"
Response.AddHeader "Content-Disposition", "attachment;filename=export.csv"
struserid=Request.QueryString("uid")
set con = Server.CreateObject("ADODB.Connection")
%>
<!--#INCLUDE FILE="databaseconnection.asp"-->
<%Con.open DSNtest
set rec1=con.execute ("SELECT * FROM orders where receivedp = '0000-00-00 00:00:00' AND pid = '" & struserid & "' order by zipid asc")%>
sep=;
Address;City;State;Zip;
<%while not rec1.eof
strzipid = rec1("zipid")
set rec3=con.execute ("SELECT * FROM zip where zipcode = '" & strzipid & "'")
%>
<%=rec1("address")%>;<%=rec3("city")%>;<%=rec3("state")%>;<%=rec3("zipcode")%>;
<%rec1.movenext
wend
rec1.close
set rec1 = nothing
rec3.close
set rec3 = nothing
con.close
set con = Nothing%>

1 个答案:

答案 0 :(得分:1)

这里有点猜测,但是尝试将你的vbs放在一个代码块中,并使用vbcrlf在你需要的地方添加换行符 - 即

<% Con.open DSNtest
set rec1=con.execute ("SELECT * FROM orders where receivedp = '0000-00-00 00:00:00' AND pid = '" & struserid & "' order by zipid asc")
Response.write "sep=;" & vbcrlf
Response.write "Address;City;State;Zip;" & vbcrlf
while not rec1.eof
strzipid = rec1("zipid")
set rec3=con.execute ("SELECT * FROM zip where zipcode = '" & strzipid & "'")
Response.write rec1("address")&";"&rec3("city")&";"&rec3("state")&";"&rec3("zipcode") & vbcrlf
rec1.movenext
wend
'etc

关闭一段asp代码并在下一行开始一个新代码会增加一行