跳至內容
選單
此問題已被標幟
3 回覆
19233 瀏覽次數

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)


頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
1
11月 22
2498
7
9月 20
7300
7
1月 24
15113
1
11月 17
3944
0
2月 17
3166