Odoo Help


This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


How to import excel file in ODOO 9

on 10/28/15, 3:01 AM 2,048 views

I developed a custom import option for update the one2many table, for example I have a binary field for selecting xls or csv, then I have one button for import, this function will need to reterive the csv or xls data to create one2many records. In this code .csv is working fine but can't import .xls file. How to import .xls file.

    def records_import(self, cr, uid, ids, context=None):
supplier_obj = self.pool.get('res.partner')
for price in self.browse(cr, uid, ids, context=context):
fileName, fileExtension = os.path.splitext(price.file_to_import_fname)
if fileExtension != '.csv':
raise osv.except_osv(_("Warning !"), _("Change the file type as CSV"))
price_file = unicode(base64.decodestring(price.import_payment), 'windows-1252', 'strict').split('\n')
line_count = 0
ss = len(price_file)
for line in price_file:
line_count += 1
if line_count > 1:
if line_count < ss -1:
line_contents = line.split(',')
if not line_contents:
Name = line_contents[0].strip()
Amount = line_contents[1].strip()
supplier_id = supplier_obj.search(cr, uid, [('name', '=', Name)])
if supplier_id == []:
supplier = {
new_supplier = supplier_obj.create(cr, uid, supplier)
for supp in supplier_obj.browse(cr, uid, supplier_id):
new_supplier = supp.id
price_line_exist = self.pool.get('sample.lines').search(cr, uid, [('name', '=', new_supplier),('payment_id', '=', price.id),('amount', '=', Amount)])
if price_line_exist == []:
price_upload_dict = {
'name' : new_supplier,
'amount': Amount
self.pool.get('sample.lines').create(cr, uid, price_upload_dict)
self.write(cr, uid, price.id,{'upload':True},context=context)
return {}

Axel Mendoza

--Axel Mendoza--
| 6 7 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full time employee trying to understand what to do an how

Reach me at aekroft@gmail.com

Axel Mendoza
On 10/28/15, 3:37 AM

You need to use a xls/xlsx library to allow you to read that files formats and better use xlrd that read both.

Install this package


Here some examples:



You need to know from where(rows and cols) you will read the data

Péter Mikó
On 7/25/16, 8:11 AM

Hi Axel,

I am a beginner so can you help how I could install this library to our local v9 instance? Any howto link would do where I could learn installing libraries. 

Thanks in advance,


Hi Péter Mikó

In python the most used install method of libraries is using pip that is used to install libraries from


if the library does not install from pypi, then you need to check the library docs about how to install it. To install anything from pypi you could issue the command

pip install library_name

to install for example https://pypi.python.org/pypi/xlrd

pip install xlrd

there are a lot of resources out there of how to install libraries in python, also if you have an already running odoo v9 instance, you already had installed some libraries for that

Axel Mendoza
on 7/25/16, 2:21 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)


Asked: 10/28/15, 3:01 AM
Seen: 2048 times
Last updated: 7/25/16, 8:11 AM