Odoo Help


7 Answers
Jose Vasquez
2016/4/14 上午10:42


I spent a bit of code that I use, I worked for odoo9

import xlwt

from xlsxwriter.workbook import Workbook

from cStringIO import StringIO

import base64

def print_excel_report(self, cr, uid, ids, context=None):

    filename= 'detalle_cobranzas.xls'

    workbook= xlwt.Workbook(encoding="UTF-8")

    worksheet= workbook.add_sheet('Detalle de cobranzas')

    style = xlwt.easyxf('font:height 400, bold True, name Arial; align: horiz center, vert center;borders: top medium,right medium,bottom medium,left medium')

    worksheet.write_merge(0,1,0,7,'REPORT IN EXCEL',style)

    fp = StringIO()


    export_id = self.pool.get('excel.extended').create(cr, uid, {'excel_file': base64.encodestring(fp.getvalue()), 'file_name': filename}, context=context)



        'view_mode': 'form',

'res_id': export_id,

'res_model': 'excel.extended',

'view_type': 'form',

'type': 'ir.actions.act_window',

'context': context,

'target': 'new',


class inventory_excel_extended(models.Model):

_name= "excel.extended"

excel_file = fields.Binary('Dowload report Excel')

file_name = fields.Char('Excel File', size=64)

in xml

        <!-- Add button in your xml form -->
        <button name="print_excel_report" string="Print Excel"/>
        <!-- xml excel -->
        <record id="view_excel_form_extended" model="ir.ui.view">
<field name="name">excel.extended.form</field>
<field name="model">excel.extended</field>
<field name="arch" type="xml">
<form string="Excel Report file">
<field name="excel_file" readonly="1" filename="file_name"/>
<field name="file_name" invisible="1"/>
<record id="action_excel_form" model="ir.actions.act_window">
<field name="name">Reportes Excel</field>
<field name="view_id" ref="view_excel_form_extended"/>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="res_model">excel.extended</field>
<field name="target">new</field>

I hope you helps, Greetings.

Jignesh Mehta
2016/4/15 上午12:14

Thank you so much Jose.

Jignesh Mehta
2016/4/15 上午1:08

How to add image in the xls report. It gives me error :- Exception: String longer than 32767 characters

Jose Vasquez
2016/4/15 上午9:12

Hi Jignesh, This could serve you. http://xlsxwriter.readthedocs.org/en/latest/page_setup.html

2019/4/4 下午12:45

Hola Jose, use tu código, pero al pulsar el botón que creé no me genera el archivo xls. Podrías ayudarme con esa parte ?. Muchas gracias.

Anh Vu
2016/4/14 上午5:41


I prefer to use report_xls -> https://github.com/OCA/reporting-engine


1 Comment
Odoo Honduras
2016/4/14 下午8:11

Any user manual to use it??

Ask a Question
Keep Informed
1 follower(s)
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.