[Zope] CSV (Was: Perl scripts)

Tino Wildenhain tino@wildenhain.de
Wed, 16 Oct 2002 16:51:22 +0200


Hi,

for the buggy-as-hell Excel, the trick is to name
the .csv File .xls
Then Excel can split the columns correctly.

Regards
Tino

--On Mittwoch, 16. Oktober 2002 16:13 +0200 Andreas Tille <tillea@rki.de> 
wrote:

> 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 hint wass quite helpful - at least I get reasonable effects under
> Linux with Galeon - this handles the resulting file with Gnumeric as
> default. But strangely enough it works not in every case with the very
> same URL returning the very same result.  Sometimes Gnumeric can't handle
> the response and fails to interpret it.  This is really strange because
> saving the result as file and loading it afterwards with Gnumeric works
> perfectly.
>
> I've got my hands on an Excel 97 installation running under NT.  Here
> loading of the response failed because the whole table was interpreted
> as a single column of a string with several comma delimited entries.
>
> I tried to create a table in this Excel version and save it as cvs.  The
> observation was that it is not comma (',') separated but semicolon (';')
> separated.  When I tried this the effect in Gnumeric was unchanged
> (working *sometimes* directly - loading after saving was always perfect).
> But the situation in Excel did not change at all.
>
> I just tried to write a Python script which exactly produced what
> I've got from Excel saving as csv - Excel failed to load it correctly.
>
> The only way to get it right into Excel was to produce a file which
> has each field value enclosed into '"' (no there are no ',' in any
> of the values), to save the file with Netscape and then Excel was
> able to read the file which was not possible directly.  IE version 5.5
> is not even able to save uch kind of file as Excel file.
>
> Resume: If there is no solid way to export robust CSV which Excel is
> able to cope with I have to come back to my first question:  How to
> use Perl in Zope.  (And yes, I know Excel sucks - but this does not help.)
>
> Kind regards
>
>         Andreas.
>
>
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )