[英]Read xlsx from uploaded binary field, Odoo 15
I need to get values from already uploaded xlsx field.我需要从已上传的 xlsx 字段中获取值。 How can I do it?
我该怎么做?
This my binary field:这是我的二进制字段:
project_documents_mts_l0 = fields.Binary(string='MTS - Teklif')
When i get the Integer value from xlsx file, want to put this field:当我从 xlsx 文件中获取 Integer 值时,想要输入此字段:
field_source_budget_project = fields.Float(string='Proje', default=0, compute="_field_source_budget_project")
Extracted from some code I wrote some months back.从我几个月前写的一些代码中提取。 You need the xlrd library https://xlrd.readthedocs.io/en/latest/ :
您需要 xlrd 库https://xlrd.readthedocs.io/en/latest/ :
from xlrd import open_workbook
import base64
excel_file = base64.b64decode(self.ms_file)
wb = open_workbook(file_contents=excel_file)
sheet = wb.sheets()[0]
for row_index in range(0, sheet.nrows):
row = sheet.row(row_index)
for cell in row:
print(cell.value)
That will look through every cell in every row in the workbook, printing it.这将查看工作簿中每一行中的每个单元格,并将其打印出来。 You need to just extract the files you want.
您只需提取所需的文件。 My binary file field is self.ms_file in my example.
在我的示例中,我的二进制文件字段是 self.ms_file。
The xlrd library is pretty easy to use. xlrd 库非常易于使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.