Here is what I use to do that:

import motion.utility.dispatchAnalysis as dar

    @tg.expose(content_type="application/vnd.ms-excel")
    @identity.require(identity.has_permission('dispatchAnalysis'))
    def dispatchAnalysisExcel(self, *args, **kw):
        fromDate = parse(kw['fromDate'])
        toDate = parse(kw['toDate'])
        excelFile = StringIO.StringIO()
        dar.dispatchAnalysis(fromDate, toDate, excelFile)
        pdf = excelFile.getvalue()
        excelFile.close()
        return(pdf)

dispatchAnalysis.py is a program that uses xlwt to create an Excel file. Let me know if you have further questions.

    -Jim

On 3/10/2011 2:54 PM, mpearce wrote:
I'm trying to build functionality for users to download a pre-
populated Excel spreadsheet from my web server using xlrd and xlwt.
The server does not have MS Excel installed on it, which I assume is
OK. I have tried a few examples found in previous posts, however
cannot get it to work. When the link is clicked an empy file Excel is
downloaded.

from xlrd import open_workbook
from xlwt import easyxf
from xlutils.copy import copy

@expose(content_type="application/ms-excel")
def export(self, *args, **kw):
     rb = open_workbook(report.xls', formatting_info=True)
     wb = copy(rb)
     response.content_type = 'application/ms-excel'
     response.headers["Content-Disposition"] =
"attachment;filename=report.xls"
     wb.save('report.xls')
     return 'report.xls'

Any assistance would be greatly appreciated.
Thanks,
Michael


--
Jim Steil
VP of Information Technology
Quality Liquid Feeds, Inc.
608.935.2345 office
608.341.9896 cell

--
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en.

Reply via email to