ASP Export

Author
Discussion

sykes111s

Original Poster:

107 posts

255 months

Tuesday 12th August 2003
quotequote all
I have the following code on a page wich exports the data on the screen to an excel spread sheet, but only if excel is installed on that machine. Is there any way of exporting to a CSV or plain text

Response.Buffer = TRUE
Response.ContentType = "application/vnd.ms-excel"
Response.Write(htmlbody)



>>> Edited by sykes111s on Tuesday 12th August 16:24

Bonce

4,339 posts

280 months

Tuesday 12th August 2003
quotequote all
Response.ContentType = "text/plain"
Response.AddHeader "Content-Disposition", "filename=export.csv;"

sykes111s

Original Poster:

107 posts

255 months

Tuesday 12th August 2003
quotequote all
thanks bonce

I'v trided it but it writes to the screen rather then trying to save it

Bonce

4,339 posts

280 months

Tuesday 12th August 2003
quotequote all
It will do that if you merely refresh the page after changing your code. Close your browser and try again. It should bring up the file open/save box. If not, check your browser preferences.

sykes111s

Original Poster:

107 posts

255 months

Tuesday 12th August 2003
quotequote all
still no joy anymore ideas

anonymous-user

55 months

Tuesday 12th August 2003
quotequote all
Bonce said:
Response.ContentType = "text/plain"
Response.AddHeader "Content-Disposition", "filename=export.csv;"

A bit hazy from memory:

Response.ContentType = "application/octet-stream"
Response.AddHeader "Content-Disposition", "attached; filename=export.csv;"

There's an RFC that covers it somewhere - one of the MIME ones I think.

gopher

5,160 posts

260 months

Tuesday 12th August 2003
quotequote all
I've had to do this in the past, basically used the file system object to create a new text file (.csv) and wrote each row from a db query to the file (comma seperated) and vbcrlf attached to each as a string. Not very elegent but does the job.

If you want go down that road let me know I'll see if I can dig up the code for you.

Don

28,377 posts

285 months

Tuesday 12th August 2003
quotequote all
OK. We do this all the time.
Way to go is an ActiveX control that writes a file to the local file system and instantiates Excel to pick it up. You end up with absolute control over what is in the file and the ability to automate Excel to do what you want...

Down side is unless you are an MFC/ATL kind of person this gets damn complicated....and ActiveX controls are very sensitive to permissions/browsersettings bollocks on the client PC.

ben789

126 posts

264 months

Wednesday 13th August 2003
quotequote all
This should work:

Response.ContentType = "text/binary"