import openpyxl as oxl
file = 'd:\\12\\weather.xlsx'
wb = oxl.load_workbook(file)
wb.sheetnames
print(wb)
# ['Sheet1', 'Sheet2']



Odoo get excel file as binary field

if you use the following line of code in odoo you need some changes to make the file readable for openpyxl package:



import odoo
import io
import openpyxl
import base64

class MyClass(models.Model)    
    excel_file = fields.Binary()
    sheet_list = fields.Char()

    @api.onchange('excel_file')
    def _excel_file_change(self):

        excel_file = base64.b64decode(self.excel_file)
        bytestream = io.BytesIO(excel_file)
        bytestream.seek(0)
        wb = openpyxl.load_workbook(bytestream)
        self.sheet_list = wb.sheetnames
Views
1 Total Views
1 Members Views
0 Public Views
Actions
0 Likes
0 Dislikes
0 Comments
Share on Social Networks
Share Link
Share by mail

Please login to share this webpage by email.