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.
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 )
On Wed, 16 Oct 2002, Tino Wildenhain wrote:
for the buggy-as-hell Excel, the trick is to name the .csv File .xls Then Excel can split the columns correctly. I tried it with exactly the same example - without any success :-(. (Also Gnumeric shows one single column instead of three.)
Kind regards Andreas.
Hi Andres, just to make sure - try to name your script to filename.xls this works at least for us here. Regards Tino --On Mittwoch, 16. Oktober 2002 17:08 +0200 Andreas Tille <tillea@rki.de> wrote:
On Wed, 16 Oct 2002, Tino Wildenhain wrote:
for the buggy-as-hell Excel, the trick is to name the .csv File .xls Then Excel can split the columns correctly. I tried it with exactly the same example - without any success :-(. (Also Gnumeric shows one single column instead of three.)
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 )
Changing my filename suffix from csv to xls actually made things worse. From mozilla I have the same behavior: The file opens in excel but columns are not split. From IE I have new behavior: IE only asks once (instead of twice) to open file, but now excel does not split columns. It might have something to do with the excel version (I'm using 2k). It's also possible that I need to wrap each field in quotes but at this point I'm getting fed up.
-----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Tino Wildenhain Sent: Wednesday, October 16, 2002 10:54 AM To: Andreas Tille; Zope user list Subject: Re: [Zope] Re: CSV (Was: Perl scripts)
Hi Andres,
just to make sure - try to name your script to filename.xls
this works at least for us here.
Regards Tino
--On Mittwoch, 16. Oktober 2002 17:08 +0200 Andreas Tille <tillea@rki.de> wrote:
On Wed, 16 Oct 2002, Tino Wildenhain wrote:
for the buggy-as-hell Excel, the trick is to name the .csv File .xls Then Excel can split the columns correctly. I tried it with exactly the same example - without any success :-(. (Also Gnumeric shows one single column instead of three.)
Kind regards
Andreas.
I did a quick test here (Excel 2k) - when I named the file .xls I ran into the problem of Excel trying to access the document via WebDAV instead of plain HTTP (Office 2k probes for a WebDAV port when trying to open files over HTTP). You may be running into this? When I named the file .csv and set the mime-type to text/comma-separated-values it worked fine - I was prompted to open or save the file, but it opened in Excel and split the fields. It didn't matter whether the fields were quoted, but I didn't have a very complicated data set. Julian.
-----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Charlie Reiman Sent: Thursday, 17 October 2002 4:53 AM To: Tino Wildenhain; Andreas Tille; Zope user list Subject: RE: [Zope] Re: CSV (Was: Perl scripts)
Changing my filename suffix from csv to xls actually made things worse. From mozilla I have the same behavior: The file opens in excel but columns are not split. From IE I have new behavior: IE only asks once (instead of twice) to open file, but now excel does not split columns.
It might have something to do with the excel version (I'm using 2k). It's also possible that I need to wrap each field in quotes but at this point I'm getting fed up.
-----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Tino Wildenhain Sent: Wednesday, October 16, 2002 10:54 AM To: Andreas Tille; Zope user list Subject: Re: [Zope] Re: CSV (Was: Perl scripts)
Hi Andres,
just to make sure - try to name your script to filename.xls
this works at least for us here.
Regards Tino
--On Mittwoch, 16. Oktober 2002 17:08 +0200 Andreas Tille <tillea@rki.de> wrote:
On Wed, 16 Oct 2002, Tino Wildenhain wrote:
for the buggy-as-hell Excel, the trick is to name the .csv File .xls Then Excel can split the columns correctly. I tried it with exactly the same example - without any success :-(. (Also Gnumeric shows one single column instead of three.)
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 )
I have gotten something like this to work, but I used a different content type. I also didn't manually set any other headers. Excell and Gnumeric (and StarCalc for that matter) worked without problems. Jason text/comma-separated-values Andreas Tille <tillea@rki.de> writes:
On Wed, 16 Oct 2002, Tino Wildenhain wrote:
for the buggy-as-hell Excel, the trick is to name the .csv File .xls Then Excel can split the columns correctly. I tried it with exactly the same example - without any success :-(. (Also Gnumeric shows one single column instead of three.)
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 )
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.)
Well, you can always launch the perl as an external process. But if it's just generating CSV and acting as a CGI script, it should be easy to replicate that behavior from a Python script object. If the script is small post it or mail it to me. I'd be interested in seeing if it has some secret CSV knowledge that makes the data format work better. FWIW, are you sure your Perl script behaves better than the Python script you already have?
On Wed, 16 Oct 2002, Charlie Reiman wrote:
Well, you can always launch the perl as an external process. But if it's just generating CSV and acting as a CGI script, it should be easy to replicate that behavior from a Python script object. If the script is small post it or mail it to me. I'd be interested in seeing if it has some secret CSV knowledge that makes the data format work better.
FWIW, are you sure your Perl script behaves better than the Python script you already have? In the thread of this mailing list named "Perl scripts" I explained, that I would like to use the Perl module Spreadsheet::WriteExcel which outputs real xls files. I'm not really sure that it would work as plaed via calling Excel directly from the script, but after saving the obtained file the user would have a file which are perfectly viewable with Excel (and Gnumeric).
I would love if someone would port this Perl module to Python, thought. Kind regards Andreas.
-----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Andreas Tille Sent: Wednesday, October 16, 2002 10:30 PM To: Zope user list Subject: [Zope] RE: CSV (Was: Perl scripts)
On Wed, 16 Oct 2002, Charlie Reiman wrote:
Well, you can always launch the perl as an external process. But if it's just generating CSV and acting as a CGI script, it should be easy to replicate that behavior from a Python script object. If the script is small post it or mail it to me. I'd be interested in seeing if it has some secret CSV knowledge that makes the data format work better.
FWIW, are you sure your Perl script behaves better than the Python script you already have? In the thread of this mailing list named "Perl scripts" I explained, that I would like to use the Perl module Spreadsheet::WriteExcel which outputs real xls files. I'm not really sure that it would work as plaed via calling Excel directly from the script, but after saving the obtained file the user would have a file which are perfectly viewable with Excel (and Gnumeric).
I would love if someone would port this Perl module to Python, thought.
Kind regards
Andreas.
Woof. Wow. I had a look at this perl package and it is impressive. In addition to the grunty icky work of supporting the OLE file format, it also posseses a forumla parser, cell layout support, image placement (and possible embedding, not sure), text formatting... It's quite impressive and would take quite a bit of time and lots of testing to port in all its glory. The good news is it doesn't appear to use any COM stuff or external C packages so it should be pretty easy to port the core data file stuff. It's also good code with clean layout and comments so it's easy to figure out what is going on. Unfortunately, I don't have time and it isn't a priority for my employer right now.
On Thu, 17 Oct 2002, Charlie Reiman wrote:
Woof. Wow. I had a look at this perl package and it is impressive. In Yes. It is. :) I definitely use a small subset of its power. But even the simple script I wrote to export some data from a database and build Excel-Output caused much less trouble than CSV. (While I know that XLS is no standard at all I was perfectly able to work with the XLS in Excel *and* Gnumeric - I did not found a CSV-From which fits this criterium yet.)
The good news is it doesn't appear to use any COM stuff or external C packages so it should be pretty easy to port the core data file stuff. It's also good code with clean layout and comments so it's easy to figure out what is going on. Unfortunately, I don't have time and it isn't a priority for my employer right now. So back to the original topic: Is there any example how to use an external Perl script and shipping some parameters to it? I just found the statement that it is possible. I wonder if anybody tried ...
Kind regards Andreas.
So back to the original topic: Is there any example how to use an external Perl script and shipping some parameters to it? I just found the statement that it is possible. I wonder if anybody tried ...
http://www.zope.org/Members/andym/wiki/SampleApp http://www.zope.org/Members/andym/wiki/SampleApp2 and more is outlined in the (ugh PowerPoint) presentation here http://www.zope.org/Members/andym/ZopePerl.ppt -- Andy McKay www.agmweb.ca
On Fri, 18 Oct 2002, Andy McKay wrote:
http://www.zope.org/Members/andym/wiki/SampleApp Thanks for the links. I think I've found the problem why I failed here. Your wrote:
Then create a regular Perl Script (not an *unrestricted* Perl Script) by visiting the Zope management interface and choosing "Script (Perl)" from the "Add" dropdown. Give it the following body and arguments: There is no "Script (Perl)" entry in my installation and I found no hint to a product which provides this functionality in my Zope 2.5.1 installation (Debian GNU/Linux 3.0). I guess I have to install the zope-perl stuff from ActiveState, right?
http://www.zope.org/Members/andym/wiki/SampleApp2
and more is outlined in the (ugh PowerPoint) presentation here
http://www.zope.org/Members/andym/ZopePerl.ppt Tried it with ppthtml and got a reasonable document to view. I wonder how I could get "Perl Script (Unrestricted)". I guess here the same problem if missing zope-perl?
Thanks Andreas.
On Monday 21 October 2002 18:30, Andy McKay wrote:
Yes, Zope Perl doesn't come with Zope. You have to install it. But dont worry, usually installing it is the hardest part. No. Easiest. Hardest part is when you try to read your own source. After half of year... ;-)
-- Regards, Bogdan A computer without any MS Windows is like a fish without a bicycle. -- With apologies to Gloria Steinem
On Mon, 21 Oct 2002, Andy McKay wrote:
I guess I have to install the zope-perl stuff from ActiveState, right?
Yes, Zope Perl doesn't come with Zope. You have to install it. But dont worry, usually installing it is the hardest part. I found the "Installing Zope-Perl on Debian" HOWTO ( http://www.zope.org/Members/ajlouie/zoperl ) . As a Debian maintainer I wonder if I would really need commercial products like ActivePerl and ActivePython to run Zope-Perl. Please do not missunderstood this lines: It is really OK what companies like ActiveState do and they do a good job for the Open Source community. But we as Debian project are just not allowed to ship this kind of software for legal reasons.
When I find a useful program I try to integrate it into Debian and thus I wonder if there is any way to go with free tools to enable Perl in Zope. What is the main difference of the Active{Perl,Python} distributions which make them a prerequisite for zope-perl? Kind regards and thanks for the hint Andreas.
participants (7)
-
Andreas Tille -
Andy McKay -
Bo M. Maryniuck -
Charlie Reiman -
Jason Earl -
Julian Melville -
Tino Wildenhain