TOM BURKHARDT
asked on
ASP export MySQL table as comma-separated CSV file
hi experts,
Working with classic ASP and a MySQL database. I have a function which displays a recordset and can also optionally export an Excel spreadsheet based on that recorset, by adding the code
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", "attachment; filename=" & fileName & ".xls"
When a table gets over a certain size, this can slow things down.
What I would like to do is be able to export a MySQL table directly from the database, as a comma-separated CSV file. I can easily do that using MySQL-Front, but would like to give my clients the ability to do this themselves.
Is there an ASP VBScript out there to do this?
Working with classic ASP and a MySQL database. I have a function which displays a recordset and can also optionally export an Excel spreadsheet based on that recorset, by adding the code
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", "attachment; filename=" & fileName & ".xls"
When a table gets over a certain size, this can slow things down.
What I would like to do is be able to export a MySQL table directly from the database, as a comma-separated CSV file. I can easily do that using MySQL-Front, but would like to give my clients the ability to do this themselves.
Is there an ASP VBScript out there to do this?
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
you can use ASP. However you cannot bypass the table output. Here is what I usually do. I have my page that displays the records how I want them formatted. Then my "Export To Excel" link, links to a seperate page that has no formatting at all, but still contains all my recordset coding, and table tags, and that code that I posted above at the top of that second page. I usually code this link as either a popup, or a target="_blank", but it does not display anything, it simply changes the content-type to ms-excel and prompts to save or open....
In order to export any data from any source from a webpage to an excel file, you need to at least have one table. The coding for the table is what tells excel to put what data in what columns....
In order to export any data from any source from a webpage to an excel file, you need to at least have one table. The coding for the table is what tells excel to put what data in what columns....
ASKER
okay, thanks, I won't shoot the mesenger. And you have answered my question.
I had hoped there was some way to export directly from the database to a file, perhaps using a File Scripting Object, but I guess even that would still only put it on the Server, not on the user's computer.
I had hoped there was some way to export directly from the database to a file, perhaps using a File Scripting Object, but I guess even that would still only put it on the Server, not on the user's computer.
ASKER
BTW, "Response.Buffer = True" is the default since IIS 5
tom
tom
you're right, and False is default for IIS 4 and under, so everything I write, if I need buffering, I make it true where needed. Not everybody is out of the dark ages...
ASKER