You are here: Home OpenERP Developing Export something into Excel
Search
Advanced Search…
E-Mail

Webmail: webmail.wyden.com

E-Mail Preferences: postfix.wyden.com/users

E-Mail Administration: postfix.wyden.com

Statistics
Total: 473
Total Pages: 286
Total Folders: 87
Total Files: 18
Total Links: 26
Last modification: 19.04.2012 15:21
 

Export something into Excel

by Wyden Silvan last modified 18.06.2010 11:52

Install xlwt 0.7.2 (http://pypi.python.org/pypi/xlwt)

Example1:

**************************************

from xlwt import Workbook
import cStringIO

f = cStringIO.StringIO()
wb = Workbook()

ws = wb.add_sheet('Hey, Dude')
wb.save(f)

f.seek(0)
print f.read()

****************************************

Example2:

****************************************

import base64
from osv import fields,osv
from tools.translate import _
import time
import cStringIO
import xlwt
from datetime import datetime

def create_report(self,cr,uid,ids,context={}):
        this = self.browse(cr, uid, ids)[0]

        #definition of styles and formats
        style_header = xlwt.easyxf('font: bold on;')
        style_date = xlwt.easyxf(num_format_str='DD.MM.YYYY')
        style_cur = xlwt.easyxf(num_format_str="[$SFr.]" + " 0.00")

        #creating the excel file
        wb = xlwt.Workbook()
        #creating a sheet in the excel file with name 'test'
        ws = wb.add_sheet('test')

        ws.write(0,0,'Datum Rechnung', style_header)
        ws.col(0).width = 4400
        ws.write(1,1,'Status Rechnung', style_header)
        ws.col(1).width = 4400

        #defining the buffer
        f = cStringIO.StringIO()
        #save the file in the buffer
        wb.save(f)
        #encode the buffer
        out=base64.encodestring(f.getvalue())
        #return the excel file as a save/open dialogue
        return self.write(cr, uid, ids, {'state':'get', 'data':out, 'name':'export.xls'}, context=context)

Report()