[Zope] Re: CSV (Was: Perl scripts)

Andreas Tille tillea@rki.de
Tue, 22 Oct 2002 13:06:48 +0200 (CEST)


On Fri, 18 Oct 2002, Warnes, Gregory R wrote:

> ##
> ## Configuration
> ##
>
> ## Perl Path
> PERL_PATH='/usr/local/bin/perl'
>
> ## Location of perl script 'xls2csv.pl'
> XLS2CSV_PATH = '/usr/local/zope/current/Extensions/xls2csv.pl'
>
> # ... other stuff here ...
>
>
> def
> ExcelToCSV(ExcelData=None,ExcelName='ExcelFile.xls',CSVName='CSVFile.csv'):
>    """Translate  the first worksheet of a Microsoft Excel file to CSV
>       format by calling the perl script 'xls2csv.pl'
>    """
> ...
>    if retval==0:
>       csvfile = open(CSVName,"r")
>       CSVData = csvfile.read()
>       csvfile.close()
>    else:
>       CSVData = None
>
>    clean_tmpdir(dirinfo)
>
>    return CSVData

This works like a charm and I'm very happy with this solution.  The only
thing I would like to do now is the equivalent of

    response.setHeader('Content-type', 'application/vnd.ms-excel')
    response.setHeader('Content-Length', len(result_str))
    response.setHeader('Content-Disposition','attachment;filename=filename.csv')

which I did in a Python Script.  In short - how to reference the response
opject inside an External Method.

Kind regards

          Andreas.