Skip to Content
Menu
This question has been flagged
3 Replies
17830 Views

Hello

I would like to import some line with a wizzard, I defined a fields.benary

I can't read the file with

workbook = xlrd.open_workbook

I get this error:

File "/usr/lib/python2.7/dist-packages/xlrd/__init__.py", line 394, in open_workbook f = open(filename, "rb")

IOError: [Errno 36] File name too long: '0M8R4KGxGuEAAAAAAAAAAAAAAAAAAAAAOwAD

 

Avatar
Discard
Author Best Answer

answer:

imported=self.browse(cr, uid, ids, context=context)[0]
file_path = tempfile.gettempdir()+'/file.xls'
data = imported.file_import
f = open(file_path,'wb')
f.write(data.decode('base64'))
f.close()
workbook = xlrd.open_workbook(file_path)

Avatar
Discard
Best Answer

from xlrd import open_workbook

import base64

file = fields.Binary(string='Xls file', required=True)

 def fct(self):

...

...

file_data = base64.b64decode(self.file)

wb = open_workbook(file_contents=file_data)

sheet = wb.sheet_by_index(0)

values = sheet._cell_values

Avatar
Discard
Best Answer
from xlrd import open_workbook


file = fields.Binary(string='Xls file', required=True)
 
def fct(self):
...
...
file_data = self.file.decode('base64')
wb = open_workbook(file_contents=file_data)


Avatar
Discard
Related Posts Replies Views Activity
1
Nov 22
1507
7
Sep 20
5993
7
Jan 24
13937
1
Nov 17
2746
0
Feb 17
2301