So speichern Sie die XLSX -Datei in ir_attachment odoo

from cStringIO import StringIO
import base64

workbook = xlsxwriter.Workbook('demo.xlsx')
worksheet = workbook.add_worksheet()
worksheet.set_column('A:A', 20)

# Code for XLSX

fp = StringIO()
workbook.save(fp)
fp.seek(0)
datas = base64.encodestring(fp.read())
file_name = "demo.xlsx"
attachment_data = {
'name':file_name,
'datas_fname':file_name,
'datas':datas,
'res_model':"modelname",
}
self.env['ir.attachment'].create(attachment_data)
NazirWazir