asp导出记录到execl/csv

方式一:

<%
Dim ranNum,FileUrl,MyFile

Randomize

ranNum=Int(90000*Rnd)+10000 ' 随机输出五位数

Set Fso=CreateObject("Scripting.FileSystemObject")

FileUrl=Server.MapPath (ranNum&".xls")

If Fso.FileExists(FileUrl) Then
 Response.Write "相同文件名的文件已经存在!"
Else
 Set MyFile=Fso.CreateTextFile(FileUrl,true)
 MyFile.WriteLine("第一列"&chr(9)&"第二列"&chr(9)&"第三列")
 
 For i=1 To 10
  MyFile.Writeline("'00001"&i&chr(9)&"'00002"&i&chr(9)&"'00003"&i)
 Next
 
 Response.Write "<a href="""&ranNum&".xls"">点击下载</a>"
End If
%>

方式二:

Dim ranNum,i

Randomize

ranNum=Int(90000*Rnd)+10000 ' 随机输出五位数

Response.AddHeader "Content-Disposition", "attachment;filename="&ranNum&".xls"
Response.ContentType = "application/vnd.ms-excel"
Response.Write "第一列"&vbtab&"第二列"&vbtab&"第三列"

For i=1 To 10
 Response.Write vbcrlf
 Response.Write "'00001"&i&vbtab&"'00002"&i&vbtab&"'00003"&i
Next

方式三:

Dim ranNum,m,n

Randomize

ranNum=Int(90000*Rnd)+10000 ' 随机输出五位数

Response.AddHeader "Content-Disposition", "attachment;filename="&ranNum&".xls"
Response.ContentType = "application/vnd.ms-excel"
Response.Write "<table border=""1"">"
Response.Write "<tr><td>第一列</td><td>第二列</td><td>第三列</td></tr>"
For m=1 To 10
 Response.Write "<tr>"
 For n=1 To 3
  Response.Write "<td style=""mso-number-format:\@"">0000"&n&m&"</td>"
 Next
 Response.Write "</tr>"
Next
Response.Write "</table>"

方式四:csv

Dim ranNum,FileUrl,MyFile

Randomize

ranNum=Int(90000*Rnd)+10000 ' 随机输出五位数

Set Fso=CreateObject("Scripting.FileSystemObject")

FileUrl=Server.MapPath (ranNum&".csv")

If Fso.FileExists(FileUrl) Then
 Response.Write "相同文件名的文件已经存在!"
Else
 Set MyFile=Fso.CreateTextFile(FileUrl,true)
 MyFile.WriteLine("第一列,第二列,第三列")
 
 For i=1 To 10
  MyFile.Writeline("'00001"&i&",'00002"&i&",'00003"&i)
 Next
 
 Response.Write "<a href="""&ranNum&".csv"">点击下载</a>"
End If

你可能感兴趣的:(asp,导出,csv,execl)