On Wed, Jul 20, 2011 at 5:45 AM, Vineet <[email protected]> wrote:
> I was looking for a library to export data to OpenOffice & Excel.
> I found 2 such open source projects.
>
> For OOO ---
> http://ooolib.sourceforge.net/
>
> For Excel ---
> http://www.python-excel.org/
>
> What I intend to do is, keep the classes in web2py folder, import the
> classes in controller, then parse the result fetched from MySQL and
> export the data to OOO or Excel.
>
> Reasons as to why I am posting it here are--
>
> 1] Whether anybody has tried these and knows if these are mostly bug-
> free (may not be 100%)
> 2] Whether anybody knows any other (better suited, may be) projects
> like these (considering integration into w2p, feature-rich, tested,
> etc.)
> 3] To share my findings with the list (might be useful to someone
> new).
>
> Cheers
> :-)
Hi Vineet,
I used xlwt for a non-production site and worked fine for me (just a
very simple report with a small formatting).
This is a quick example:
def excel_report():
from datetime import datetime
import xlwt
tmpfilename=os.path.join(request.folder,'private',str(uuid4()))
font0 = xlwt.Font()
font0.name = 'Arial'
font0.bold = True
style0 = xlwt.XFStyle()
style0.font = font0
style1 = xlwt.XFStyle()
style1.num_format_str = 'DD-MMMM-YYYY'
wb = xlwt.Workbook()
ws = wb.add_sheet('Sample report')
ws.write(0, 0, 'Text here', style0)
ws.write(0, 6, 'More text here', style0)
ws.write(0, 7, datetime.now(), style1)
wb.save(tmpfilename)
data = open(tmpfilename,"rb").read()
os.unlink(tmpfilename)
response.headers['Content-Type']='application/vnd.ms-excel'
return data
Hope it helps you.
Joaco.