Odoo Help

0

0
3 Answers
0
Samo Arko
10/30/18, 5:26 AM

Figured it out.

inputx = StringIO.StringIO()
inputx.write(base64.decodestring(self.excel_file_for_import))
book = open_workbook(file_contents=inputx.getvalue())




0
Avatar

Mitul Shingala

--Mitul Shingala--

2294
| 6 3 9
Rajkot, India
--Mitul Shingala--

Odoo Developer

Mitul Shingala
10/30/18, 5:17 AM

hello

try like below code

import xlrd
import tempfile
import binascii 
def method_name(self):
        fp = tempfile.NamedTemporaryFile(suffix=".xlsx")
        fp.write(binascii.a2b_base64(self.xls_file)) # self.xls_file is your binary field
        fp.seek(0)

        workbook = xlrd.open_workbook(fp.name)
        sheet = workbook.sheet_by_index(0)

        for row_no in range(sheet.nrows):
            if row_no <= 0:
                fields = map(lambda row:row.value.encode('utf-8'), sheet.row(row_no))
            else:
                line = (map(lambda row:isinstance(row.value, unicode) and row.value.encode('utf-8') or str(row.value), sheet.row(row_no)))
                # in above line variable, you get the line by line value of excel file rows.
1 Comment
Tabla d.o.o., Samo Arko
10/30/18, 5:25 AM

figured it out. used StringIO()

Ask a Question
Writer
Keep Informed
1 follower(s)
About This Community

This platform 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.

Register
Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now