Add the possibility to extract data from a sql query toward an excel file. It is also possible to provide an template excel file for a query. In this case, the data will be inserted in the specified sheet of the provided excel file. This is usefull when doing a lot of calculation in excel and the data is coming from Odoo.
Table of contents
If you want Odoo to update an existing excel file, you should create an attachment with the excel file and configure this attachment on the query. Then, you can configure the query to indicate if Odoo should export the header and where it should insert the data. By default, it will insert it in the first sheet, at first row/column.
This module extends sql_export to add Excel (.xlsx) as an output
format. Two modes are available: generating a fresh Excel file from the
query results, or inserting the results into a pre-defined Excel
template.
Generate a fresh Excel file
- Open an existing SQL export query, or create a new one as documented
in
sql_export. - Define the SQL query.
- Run the export and select the Excel output. The resulting
.xlsxcontains the column headers (if enabled) and one row per result row.
Insert results into an Excel template
This mode is useful when the final report relies on Excel formulas, charts, or formatting that should be preserved across exports.
- Prepare your
.xlsxtemplate locally. Leave empty the cells where the query results should be written. - Attach the template file to the query record.
- Configure where the data should be inserted: target sheet, start row, start column, and whether to include the header row.
- Run the export. The template is opened, the query results are written at the configured position, and the updated file is returned.
Any formulas or charts in the template that reference the inserted cells are recalculated when the file is opened.
Example: monthly sales summary
A typical use case is a recurring report where the layout and calculations live in Excel, and only the raw data changes.
Suppose the template sales_summary.xlsx contains:
- Sheet 1 - Data: empty, will receive the query results.
- Sheet 2 - Summary: pivot tables and charts referencing Sheet 1.
Define the SQL query, for example:
SELECT
partner.name AS customer,
SUM(line.price_subtotal) AS revenue
FROM sale_order_line line
JOIN sale_order so ON so.id = line.order_id
JOIN res_partner partner ON partner.id = so.partner_id
WHERE so.state IN ('sale', 'done')
AND so.date_order >= date_trunc('month', CURRENT_DATE)
GROUP BY partner.name
ORDER BY revenue DESC;
Attach sales_summary.xlsx to the query, set the target sheet to
Data, include the header, and start at row 1, column 1. Each export
then produces an up-to-date version of the report, with the pivots and
charts on Sheet 2 refreshed automatically when the file is opened.
Notes
- The variable substitution patterns documented in
sql_export(such as%(company_id)sand%(user_id)s) also apply to this module. jsonbcolumns in the query result are serialised before being written to the Excel file.
Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us to smash it by providing a detailed and welcomed feedback.
Do not contact contributors directly about support or help with technical issues.
- Akretion
- Florian da Costa <florian.dacosta@akretion.com>
- Helly kapatel <helly.kapatel@initos.com>
This module is maintained by the OCA.
OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.
Current maintainer:
This module is part of the OCA/reporting-engine project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.





