Thanks, Massimo! I added the following line before the return statement of
the "gimme()" function, and it works perfectly now:
response.headers['Content-Type']=
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
On Tuesday, November 4, 2014 6:30:06 PM UTC-5, Massimo Di Pierro wrote:
>
> You need one action to return the data stream and one to create a link:
>
> def gimme():
> poll_id = request.args(0,cast=int)
> import xlsxwriter
> import cStringIO
>
> stream = cStringIO.StringIO()
>
> ...
>
> workbook = xlsxwriter.Workbook(stream)
> worksheet = workbook.add_worksheet(...)
>
> ...
>
> stream.seek(0)
> return response.stream(stream)
>
>
> def create_excel_link(poll_id):
> return A('link', _href = URL('gimme',args=poll_id))
>
>
>
> On Tuesday, 4 November 2014 16:53:02 UTC-6, Spokes wrote:
>>
>> I'd like to create an excel file, and create a link for it within a page,
>> without writing the file to disk. I've been trying to do something like this
>> :
>> def create_excel_link(poll_id):
>> import xlsxwriter
>> import cStringIO
>>
>> stream = cStringIO.StringIO()
>>
>> ...
>>
>> workbook = xlsxwriter.Workbook(stream)
>> worksheet = workbook.add_worksheet(...)
>>
>> ...
>>
>> stream.seek(0)
>>
>> return A('link', _href = stream.read())
>>
>> The above idea works with images (i.e. with the IMG helper, although I've
>> been advised that this is not the most efficient way of going about it),
>> but I'm not sure how to make it work with excel files. Is it possible to
>> modify this or do something comparable in order to generate an excel file
>> without writing it to disk, and to present a link to it? Thank you.
>>
>>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.