Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3 Trả lời
19249 Lượt xem

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

 

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

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)

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất
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)


Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 11 22
2509
7
thg 9 20
7306
7
thg 1 24
15133
1
thg 11 17
3950
0
thg 2 17
3172