Dear All,
I can create and download reports xlsx format using xlsxwriter. I need to convert xlsx file to zip and download. with the below code, i can create abc.zip file with excel, but the excel file contain base64 raw data.(same as file_download). Any help is highly appreciated.
# create xlsx file
fp = BytesIO()
workbook = xlsxwriter.Workbook(fp)
....MycodeHere....
....MycodeHere....
workbook.allow_zip64
workbook.close()
file_download = base64.b64encode(fp.getvalue())
fp.close()
# create Zip File
pyzip = PyZip()
pyzip['excel.xls'] = file_download
zip_bytes = pyzip.to_bytes()
# create attachment
attachment_obj = self.env['ir.attachment']
attachment_id = attachment_obj.create(
{'name': "name", 'datas_fname': 'abc.zip', 'datas': zip_bytes})
att_ids.append(attachment_id.id)
# prepare download url
download_url = '/web/content/' + str(attachment_id.id) + '?download=true'
# download
return {
"type": "ir.actions.act_url",
"url": str(download_url),
"target": "new",
}