Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

How to save XLSX file to 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)
 
PREVIOUS NEXT
Tagged: #How #save #XLSX #file #odoo
ADD COMMENT
Topic
Name
6+4 =