Community mailing list archives

community@mail.odoo.com

Re: how to read XLS file in Odoo

by
initOS GmbH, Torsten Francke
- 09/12/2014 07:50:31
Hi,

We read xls files with xlrd python lib [1] and this works really great.
We combine this with our connector_flow [2] module. But no need for
this. So first Task reads xls and make chunks of rows. The second task
import the chanks in what ever you need.

In our use case we implemented this to import a excel list with
inventory correction.

So the mayn code looks like:

from xlrd import open_workbook

#it is meta object of ir.attachment
file_obj = self.session.pool.get('impexp.file')
f = file_obj.browse(self.session.cr, self.session.uid, file_id)
data_file = b64decode(f.attachment_id.datas)

wb = open_workbook(file_contents=data_file)
for s in wb.sheets():
    for row in range(s.nrows):
        data_row = []
        for col in range(s.ncols):
            value = (s.cell(row, col).value)
            data_row.append(value)

The Code is part of a bigger module where all the mapping stuff is hard
codet so we need to make a complete example but at the moment not time
for this.

Kind Regards

Markus


[1] https://pypi.python.org/pypi/xlrd
[2] http://bazaar.launchpad.net/~initos.com/+junk/connector_flow/files

On 11.09.2014 16:15, abhishek jaiswal wrote:
> Hi all,
> 
> Can any body please tell how to read and process excel file in Odoo or
> any example
> 
> it will be very help full thanks
> 
> -- 
> With Warm Regards
> Abhishek Jaiswal,
> 
> _______________________________________________
> Mailing-List: https://www.odoo.com/groups/community-59
> Post to: mailto:community@mail.odoo.com
> Unsubscribe: https://www.odoo.com/groups?unsubscribe
> 

-- 
Dipl.-Comp.-Math. Markus Schneider
Softwareentwickler

initOS GmbH & Co. KG
An der Eisenbahn 1
21224 Rosengarten

Mobil:   +49 (0)172 2303699
Phone:   +49 (0)4105 5615613
Fax:     +49 (0)4105 5615610

Email:   markus.schneider@initos.com
Web:     http://www.initos.com

Geschäftsführung:
Dipl. Wirt.-Inf. Frederik Kramer & Dipl.-Ing. (FH) Torsten Francke
Haftende Gesellschafterin: initOS Verwaltungs GmbH

Sitz der Gesellschaft: Rosengarten – Klecken
Amtsgericht Tostedt, HRA 201840
USt-IdNr: DE 275698169
Steuer-Nr: 15/205/21402