[Zope] Sending results of query to Excel

Richard Moon Richard Moon <richard.moon@nec.ac.uk>
11 Apr 2000 16:31:39 +0100


Results of the experiments so far (thanks for all the help)

If you set the RESPONSE variable as follows (which I suspect sets a mime type whcih my browser doesn't recognise) then IE 5 will download the file for you. If the DTML method that contains this code is called something.csv then Excel will happily open up the file as a spreadsheet (I'm getting some blank lines at the top though).

Interestingly this also works with Netscape 4 on a Mac, though Netscape gives you the extra option of opening the file directly with an application. However if you do this then Excel doesn't recognise the commas and each line of output goes into one column. hmmm. If you save the file to disc then you have to open the file from within Excel as the Mac doesn't recognise the Windows .csv file extension. What I don't know is how you tell the Mac its an Excel file (anyone ???)

Here's a sample of code that works

<dtml-call "RESPONSE.setHeader('Content-Type', 'application/x-csv')">

<dtml-in Org_search>
<dtml-if sequence-start>
Name,Town,Post code,Telephone,Org.code     
</dtml-if sequence-start>
<dtml-var name null="">,<dtml-var town null="">,<dtml-var post_code null="">,<dtml-var telephone null="">,<dtml-var code null="">
</dtml-in>

Note that any spaces or newlines are interpreted by Excel so you have to run things together on one line as I have done.

Interestingly if you leave out the setting of RESPONSE then IE5 opens up Excel inside the browser (if the DTML method is called something.csv, though as with the Mac it doesn;t format it properly, everythig is in one column). 



I think I need to research the mime types properly now (unless anyone else has any ideas ?)



On 4/11/00, Jerome Alet <alet@unice.fr> wrote:

Note that any spaces 

>On 11 Apr 2000, Richard Moon wrote:
>
>> Thanks for the help - I don't see why this shouldn't work with 
>Zope - I
>> just need to find out how to get that Content-type header in the 
>object
>> Zope is serving up. 
>
>yes, and then it should work fine.
>
>IMHO this should be something like:
>
><dtml-call "RESPONSE.setcontenttype('text/yourname')">
>
>(not tested, and I'm even not sure about the function name, however 
>I'm
>almost sure you have to use RESPONSE.
> 
>then a <dtml-in ...> to loop in your selected records, however you'll
>have to display all results at the same time, not on a 50 results 
>by 50
>results basis just like the "normal" zope behavior. 
>
>good luck.
>
>please could you tell me the final solution, because I might be interested
>in a not so long time ?
>
>thanks.
>Jerome
>
>
>
>
>