Here's some DTML I use to generate a CSV file on the fly using data returned
from a query of a MySQL database:
<dtml-var FirstName null=''>,<dtml-var MiddleName null=''>,<dtml-var
LastName null=''>,<dtml-var Address null=''>,<dtml-var City
null=''>,<dtml-var State null=''>,<dtml-var Zip null=''>,<dtml-var Phone
null=''>,<dtml-var Fax null=''>,<dtml-var email null=''>,<dtml-var URL
null=''>,<dtml-var Birthday null=''>
Notice that formatting is kinda ugly. That's so that I don't get any
unwanted carriage returns nor any line feeds in the downloaded file.
Also, notice that the first line of the output (after the Content-Type, that
is) is a header line, which you may not want for your output. I include it
so that when the file is viewed in a spreadsheet, the user can tell what
each column is.
FYI, I found a lot of info on this technique on NIP Ltd's mailing list
archive (Thanks again NIP!!):
// -----Original Message-----
// From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of
// Oliver Bleutgen
// Sent: Friday, November 10, 2000 8:12 AM
// To: [EMAIL PROTECTED]
// Subject: Re: [Zope] Generating text/csv from DTML method, Mime Type?
// > I'm create a CSV file that I would like browsers to get the "save as"
// > dialog when they select it.
// > I'm using RESPONSE.write() to write out the CSV file, and I set the
// > Content-Type before calling RESPONSE.write
// > Netscape seems to work ok, it pops up a save box for "text/csv" and
// > "application/vnd.ms-excel".
// > However in both cases IE5.5 just ignores the data and re-requests the
// > page.
// > Does anyone know *all* the steps I need to take to get this to work
// > correctly with IE? I must be doing something wrong. I want to supply a
// > CSV file, but generated dynamically. I'm sure I'm missing a header
// > setting or something.
// Adding "Content-Disposition: attachment [; filename=bla.csv]" as
// a http-header might help...
// The part in s is optional .
// See my mail from yesterday for a bit more info
// Zope maillist - [EMAIL PROTECTED]
// ** No cross posts or HTML encoding! **
// (Related lists -
// http://lists.zope.org/mailman/listinfo/zope-dev )
Zope maillist - [EMAIL PROTECTED]
** No cross posts or HTML encoding! **
(Related lists -