Ir al contenido
Menú
Se marcó esta pregunta
3 Respuestas
19231 Vistas

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
Descartar
Autor Mejor respuesta

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
Descartar
Mejor respuesta

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
Descartar
Mejor respuesta
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
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
1
nov 22
2498
7
sept 20
7300
7
ene 24
15113
1
nov 17
3944
0
feb 17
3166