我想從經典asp導出csv。數據由Oracle DB提取。該查詢返回超過2500行。這裏是我試圖使用的代碼:使用經典asp導出csv
<%
sub Write_CSV_From_Recordset(RS)
if RS.EOF then
'
' There is no data to be written
'
exit sub
end if
dim RX
set RX = new RegExp
RX.Pattern = "\r|\n|,|"""
dim i
dim Field
dim Separator
'
' Writing the header row (header row contains field names)
'
Separator = ""
for i = 0 to RS.Fields.Count - 1
Field = RS.Fields(i).Name
if RX.Test(Field) then
'
' According to recommendations:
' - Fields that contain CR/LF, Comma or Double-quote should be enclosed in double-quotes
' - Double-quote itself must be escaped by preceeding with another double-quote
'
Field = """" & Replace(Field, """", """""") & """"
end if
Response.Write Separator & Field
Separator = ","
next
Response.Write vbNewLine
'
' Writing the data rows
'
do until RS.EOF
Separator = ""
for i = 0 to RS.Fields.Count - 1
'
' Note the concatenation with empty string below
' This assures that NULL values are converted to empty string
'
Field = RS.Fields(i).Value & ""
if RX.Test(Field) then
Field = """" & Replace(Field, """", """""") & """"
end if
Response.Write Separator & Field
Separator = ","
next
Response.Write vbNewLine
RS.MoveNext
loop
end sub
Response.Buffer = True
Response.ContentType = "text/csv"
Response.AddHeader "Content-Disposition", "attachment; filename=Export.csv"
theSQL = Session("Query")
Set RS = Connection.Execute(theSQL)
Write_CSV_From_Recordset RS
%>
<html>
<head>
<title>Excel/CSV Export</title>
</head>
<body>
</body>
</html>
但我所得到的是網站無法訪問的錯誤。我試圖通過更改內容類型和文件擴展名,甚至在頁面上顯示數據並導出到excel。這適用於更少的行數。但是當查詢獲取的記錄數量更多時,它只會導致網站無法訪問的錯誤。
有沒有人可以幫我解決這個問題。
您好我會嘗試,讓你知道結果。謝謝。 –
嗨我得到了以下錯誤 無法聯繫到此站點 http://dev.web.com/ExcelExport.asp的網頁可能暫時關閉,或者它可能已永久移動到新的Web地址。 ERR_INVALID_RESPONSE 服務器是Windows 2003計算機 –
我已將Server.ScriptTimeout = 6000添加到頁面的頂部。 –