|
| |
|
|
clum1
Posts: 762 From: Glasgow, Scotland Status: offline
|
Output Form Results to CSV - 5/7/2003 6:44:29
Whilst this is asp-based code, I' m posting here because it took me so long to find an easily implemented way of doing this. Basically, I had a need to take some user input and save it as a downloadable .csv (Comma Separated Variables) file. To save others the hassle, I' m publishing it here... (note, whilst I searched various sites - including this one - it was on w3schools.com that I finally found the stuff I needed.) <% ' Allow the page to work on test machine or intranet server ' strWriteFolder exists because the server can not write to a UNC defined ' folder (strWritefolder is pointing to the same folder as strCurrentFolder Dim host Dim strCurrentFolder, strWriteFolder host=lcase(request.servervariables(" HTTP_HOST" )) SELECT CASE host CASE " 6sy3b0j" ' my development machine strCurrentFolder = (" \\6sy3b0j\pdrive\" ) strWriteFolder = (" \\6sy3b0j\pdrive\" ) CASE " intranet1" ' my intranet server name strCurrentFolder = (" \\intranet1\shared\Project\CSV Files\" ) strWriteFolder = (" e:\shared\Project\CSV Files\" ) END SELECT dim fs,tfile set fs=Server.CreateObject(" Scripting.FileSystemObject" ) set tfile=fs.CreateTextFile(strWriteFolder & session(" GelPackID" ) & " .csv" ) tfile.WriteLine(" LOT NUMBER,LOT NAME,DATE STAMP,ID,PART NUMBER,PACK ID,POSITION" ) tfile.WriteLine Session(" LotNumber" ) & " ," & Session(" LotName" ) & " ," & Session(" DateStamp" ) & " ," & Session(" A1" ) & " ," & Session(" PartNumber" ) & " ," & Session(" GelPackID" ) & " ," & (" A1" ) tfile.close set tfile=nothing set fs=nothing %> Note, the first tfile.WriteLine sets up some column headers whilst the second one populates it with form data; you can use loops etc to cycle through your dataset. I hope this is of some help to anyone else trying to do the same thing. clum1
_____________________________
kenilweb.com; simple, effective web design "So I said to the Gym instructor "Can you teach me to do the splits?" He said "How flexible are you?". I said "I can't make Tuesdays"." Tim Vine
|
|
New Messages |
No New Messages |
Hot Topic w/ New Messages |
Hot Topic w/o New Messages |
Locked w/ New Messages |
Locked w/o New Messages |
|
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts
|
|
|