Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
3 ตอบกลับ
19255 มุมมอง

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

 

อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

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)

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด
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)


อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
พ.ย. 22
2511
7
ก.ย. 20
7307
ODOO 12 how can we generate Excel report แก้ไขแล้ว
7
ม.ค. 24
15137
1
พ.ย. 17
3952
0
ก.พ. 17
3180