Developer Guide to generate XLSX report using controller in Odoo18

ZIYAN
April 12, 2025
how-to-generate-xlsx-report

Generating dynamic Excel (XLSX) reports is a essential practical benefit of ERP systems such as Odoo and helps for easy analysis, sharing and archiving of structured data in a universally compatible format.

This document explores two separate ways to generate XLSX reports in Odoo, and provides alternatives to the conventional report_xlsx module. These solutions bring modularity and scalability through the use of Odoo’s HTTP controller. in this blog blog we are going to discover how to generate XLSX report in Odoo18 so let’s get in

https://odoo-community.org/shop/base-report-xlsx-2202

How to Generate XLSX Report Using Controller in Odoo18

To create XLSX reports, we implement a three-stage process:

1) Data preparation in a wizard.
2) File storage in a ‘common.xlsx.out’ transient model.
3 Implement a Common controller for file download.

zb_outstanding_report / views /outstanding_report_wiz_view.xml

button name="action_outstanding_report_xlsx" string="XLSX" type="object"
class="btn-primary"/>

zb_outstanding_report / wizard /outstanding_report_wiz.py

from odoo import models, fields
import io
import base64
import xlsxwriter

def action_outstanding_report_xlsx(self):
for obj in self:
data = self.read()[0]
output = io.BytesIO()
workbook = xlsxwriter.Workbook(output, {'in_memory': True})
sheet = workbook.add_worksheet('Partner Ledger')
workbook.close()
output.seek(0)
result = base64.b64encode(output.read())
report_id = self.env['common.xlsx.out'].sudo().create({
'filedata': result,
'filename': 'Partner Ledger.xls'
})

return {
'type': 'ir.actions.act_url',
'url': '/web/binary/download_document?model=common.xlsx.out&field=filedata&id=%s&filename=%s.xls' % (report_id.id, 'Partner Ledger.xls'),
'target': 'new',
}
output.close()

zb_outstanding_report /wizard /common_xlsx_out.py

from odoo import models,fields

class CommonXlsxOut(models.TransientModel):
_name = 'common.xlsx.out'

filedata = fields.Binary('Download File', readonly=True)
filename = fields.Char('Filename', readonly=True)

zb_outstanding_report /controllers / main.py

from odoo import http
from odoo.http import request, content_disposition
import base64

class Binary(http.Controller):

@http.route('/web/binary/download_document', type='http', auth="public")
def download_document(self, model, field, id, filename=None, **kw):
record = request.env[model].sudo().browse(int(id))
filecontent = base64.b64decode(record[field] or '')
if not filename:
filename = f"{model.replace('.', '')}{id}"
if not filecontent:
return request.not_found()
return request.make_response(
filecontent,
[
('Content-Type', 'application/octet-stream'),
('Content-Disposition', content_disposition(filename)),
],
)

Odoo Developers can choose two adaptable methods in Odoo for generating XLSX reports on diverse reporting requirements. The common controller approach enhances modularity and maintainability for complex reports, while the direct controller method provides a streamlined solution for simpler reporting tasks.

We specialize in Odoo ERP implementation across a broad spectrum of industries. Our proven expertise spans in Education, Healthcare, Construction, Logistics, Real-Estate, Supply Chain, and Manufacturing, contact us. We have a proven track record of successful Odoo deployments in these and other sectors.

Expand your development team in the UAE with Transines Solutions’ staff augmentation. Hire skilled Odoo Developers on demand now. If you have any questions regarding how to generate XLSX report in Odoo18 , feel free to contact us our experts are ready to assist you.

"Unlock the Full Potential of Your Business with Odoo ERP!"

"Get a Cost Estimate for Your ERP Project, Absolutely FREE!"

Get a Free Quote

Leave a Reply

Your email address will not be published. Required fields are marked *