Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CSV Download

Status
Not open for further replies.

Norman55

Programmer
Apr 27, 2006
48
GB
Can anyone help?
I am creating a Temp file on my server and then allowing the user to download the CSV file to their local computer
I am struggling when the data contains a comma though as this moves the data to a new cell in excel ?
This is the code I am using


dim fso, txtNew, txtNewName

set fso=Server.CreateObject("Scripting.FileSystemObject")
txtNewName = fso.GetTempName
txtNewName = Left(txtNewName, len(txtNewName) -3) & "csv"

set txtNew=fso.CreateTextFile(Server.MapPath(".") & "\" & txtNewName, True, False)

Dim fld, row

txtNew.Write "Transaction Date, Transaction, Amount" & vbCrLf

Do While Not MySearch.EOF
row = ""

For Each fld in MySearch.Fields
row = row & fld.value & ","
Next

'replace last comma with vbCrLF
row = left(row, len(row) -1) & vbCrLf

txtNew.Write row
mySearch.MoveNext
Loop
txtNew.close
set txtNew=nothing
set fso=nothing
 
If a cell in a csv has a comma in it then you need put it in quotes.
 
and to answer the next obvious question you use double quotes when you need quotes in a cell...

So if a cell contains: "Hey, Jude"

Then it will be like this: """Hey, Jude"""
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top