tag:blogger.com,1999:blog-11802292.post623486045455884261..comments2023-10-16T03:31:20.095-07:00Comments on Catherine: pyOraGeek: Excel reports from TurboGearsAnonymoushttp://www.blogger.com/profile/12229578427522022392noreply@blogger.comBlogger6125tag:blogger.com,1999:blog-11802292.post-14632119458492130172011-04-19T13:35:18.156-07:002011-04-19T13:35:18.156-07:00I am totally on track with Tim. Follow his direct...I am totally on track with Tim. Follow his direction and you will be creating Excel reports in no time!<br /><br />-Grahm<br /><a href="http://www.oneclickcommissions.com/excel-reports.html" rel="nofollow">Excel Reports</a>Jacobhttps://www.blogger.com/profile/00122289194997948520noreply@blogger.comtag:blogger.com,1999:blog-11802292.post-52677253662889534292009-06-29T17:33:08.563-07:002009-06-29T17:33:08.563-07:00We do this a lot, by making use of pyExcelerator:
...We do this a lot, by making use of pyExcelerator:<br /><i><br /># set some headers to indicate we are returning excel response.headers['Content-type'] = "application/excel"<br /> response.headers['Content-Disposition'] = "attachment; filename=event.xls"<br /><br />import pyExcelerator as xl<br /><br /># create an excel workbook<br />xldoc = xl.Workbook()<br />#Add a worksheet<br />mysheet = xldoc.add_sheet("Data")<br /><br />... add stuff to workbook ...<br /><br />from cStringIO import StringIO<br /># Create a file<br />buffer = StringIO() <br /># Save the excel to that file<br />xldoc.save(buffer)<br /><br /># return the raw excel stream <br />return buffer.getvalue()<br /></i><br /><br />This is all in TG2 so YMMV - for us it serves the excel up all warm and toastyStephenLnoreply@blogger.comtag:blogger.com,1999:blog-11802292.post-15230503785149397062007-06-17T10:49:00.000-07:002007-06-17T10:49:00.000-07:00see http://www.knoda.org/-> wiki -> HowtosHow to c...see http://www.knoda.org/<BR/>-> wiki -> Howtos<BR/><BR/>How to create an Excel File <BR/> install Perl Modules <BR/> Text::CSV_XS <BR/> Spreadsheet::WriteExcel <BR/> get http://search.cpan.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.18/examples/csv2xls.pl <BR/> replace <BR/> my $csv = Text::CSV_XS->new; <BR/> my $csv = Text::CSV_XS->new ({ binary => 1 }); <BR/> double quotes in the table/view used by hk_exportcvs have to be escaped by a double quote (see Text::CSV_XS docu) by using this function: <BR/> replace(field name,'"','""') <BR/> hk_exportcvs with option --charset=Latin1 <BR/> csv2xls.pl file.csv file.xls <BR/><BR/>DONEAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-11802292.post-52038067978853098852007-05-17T19:46:00.000-07:002007-05-17T19:46:00.000-07:00Several years ago I used some of the Python/COM in...Several years ago I used some of the Python/COM integration features in pywin32 to manipulate Excel spreadsheets directly. Actually we were reading existing Excel files instead of creating them, but it should work either way.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-11802292.post-27896198844949621992007-04-14T12:06:00.000-07:002007-04-14T12:06:00.000-07:00I think you can also pass a 'content_type' keyword...I think you can also pass a 'content_type' keyword arg into the @expose decorator to manually set the content type. This poster does it by hand, but the principle is similar: http://groups.google.co.uz/group/turbogears/msg/ba1d778c25fb5e65Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-11802292.post-24962805579788867922007-04-14T08:58:00.000-07:002007-04-14T08:58:00.000-07:00I once did this by simply outputting a table and c...I once did this by simply outputting a table and changing the content-type and it opened up in Excel.Anonymousnoreply@blogger.com