Spreadsheet/Xls report in odoo using report_xls

Spreadsheet displays multiple cells usually in a two-dimensional matrix or grid consisting of rows and columns. We have so many reporting softwares that will simply create spreadsheets. But the problem is, these reporting softwares may not support on all systems and also take lot of CPU time.

XLS reports are often necessary for many business organizations. Data representation and manipulation can be done in XLS file very easily. By default, Odoo doesn’t  support  XLS file creation of a report. This blog will help you to generate XLS report with wizard using an extra module report_xls and you can download it from here: XLSX Report

Here is the simple code introduction for create the spreadsheet

  1. We can define the title, header, number, date, and normal style using add_format(). For example,
                     heading_format = workbook.add_format({‘align’: ‘left’,’bold’: True, ‘size’: 14})
  2. We can add sheet to the workbook using add_worksheet() method.
            For example, work_sheet = workbook.add_worksheet(‘Payroll Sheet’)
  3. For write into the sheet,
                    For example, work_sheet.write(4,4,’Date From’,font_size)
  4. To set width of the cell,
                    For example, work_sheet.set_column(‘A:A’, 10)
  5. To add formula,
                    For example, worksheet.write_formula(20,4, ‘{=SUM(C7:C19)},normal_num_bold)

Now move on to the code

Here we are going to create an XLS report from a wizard. Wizard can be used to enter the data and based on this data we can filter the report. In this wizard, we will add some fields to filter the content of the report. So let us first look how the wizard is created.

Wizard Creation

Python file:

This is the python file created for the wizard. Here the fields start_date, end_date are filtration fields.

XML File:

This is the code for view of the wizard . In this view, the user can enter values for start date and end date. After entering the values, the user can click the ‘Print Report’ button to print the ‘Xls’ report.

Simple xls Report

For making a simple xls report in Odoo, we can go through the following steps

 – Declaring a report action

 – Defining a report

Declare a report action

In an XML file we can declare a report inside the ‘ <report></report>’  tag.

– Id:- Represents the report’s external id
– string:- Represents the Report
– model:- It is a mandatory field  which represents the model that the report will stand for
– report_type:- Type of report.  
– Name:- It is a mandatory field. It is useful for description of the report when looking for one in a list of some sort.
– File:- File Name

Defining a report

We can define a simple  report as follow.

In the above code, we have to write the last line properly. It should be like this

Classname(‘report.module_name.report_name.xlsx’, ‘model_name’)

Final output of report is given below

Comments

velez.cu: I follow yours steps, but when I press button "Print Report" I got this error Tipo de informe desconocido: xlsx: (, NotImplementedError(u'Tipo de informe desconocido: xlsx',), ) Unknown report type: xlsx: (, NotImplementedError(u'Unknown report type: xlsx',), )".

Leave a Reply

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

  1. Anonymous says:

    how to create a xls report by clicking on menu?

  2. velez.cu says:

    I follow yours steps, but when I press button “Print Report” I got this error
    Tipo de informe desconocido: xlsx: (, NotImplementedError(u’Tipo de informe desconocido: xlsx’,), )
    Unknown report type: xlsx: (, NotImplementedError(u’Unknown report type: xlsx’,), )

© 2020 Zesty Beanz Pvt Ltd All Rights Reserved.