[Zope] RE: Perl scripts

Andreas Tille tillea@rki.de
Mon, 14 Oct 2002 15:39:00 +0200 (CEST)


On Wed, 9 Oct 2002, Charlie Reiman wrote:

> Yes, this is pretty easy. Some python script to get you going:
> ---------------
> rs = some_sql_query()
>
> for item in rs:
>   result_str += (str(item.DATE) + ',' +
>                  str(item.STUFF) + ',' +
>                  str(item.MORESTUFF) + '\n')
>
> response.setHeader('Content-type', 'application/vnd.ms-excel')
> response.setHeader('Content-Length', len(result_str))
> response.setHeader('Content-Disposition',
> 'attachment;filename=filename.csv')
> return result_str
> ----------------
>
> Be warned that mozilla doesn't handle this quite right. It launches excel
> and hands it the data but seems to translate the EOL characters in the
> process so excel refuses to split the columns. Ironically, Excel 2000 only
> accepts the unix EOL character for csv data. So: it works fine from IE but
> not so fine from Mozilla. If anyone has a dual browser solution I'd like to
> see it.
This hins quite helpful - at least I get reasonable effects under Linux
with Galeon - this handles the resulting file with Gnumeric as default.
(I have not tested it with Excel - because of a lack of a running Excel
installation but it seems promissing.)

The only drawback is that I did not found a way to specify sane table
headings like

      "DATE"   |    "STUFF"   |   "MORESTUFF"
   ---------------------------------------------
    2002-7-17  | some stuff   | some more stuff
      ...      |   ...        |    ...

Any way to do this with csv??

Kind regards and thanks for the hint

         Andreas.