Skip to Content
Menu
This question has been flagged
3 Replies
2882 Views

My friend,

        I want to know how to create execl file in odoo 10 and let the user save it in local client machine.

Thank you.

Avatar
Discard

Hello haolingca,

Did you mean Excel report in Odoo?

Please update your question with which view, model and whether report or custom one

Best Answer

Hello Haolingoa,

To create an Excel file, you should used the library "xlwt".

In the first time you must created a "TransiantModel", in this model you create a "fields.Binary". This binary field will be your "Download link". 

class YourWizard(models.TransiantModel):
     _name = "your.wizard"
     
     your_excel = fields.Binary(string="Your excel")
     
After you generated your excel with library "xlwt" (Documentation; https://xlwt.readthedocs.io/en/latest/) or one other library to create excel file with python.

In the last step you need to write the new excel file created in the field Binary, for this you should used "StringIO" and "Base64".

After you have create you excel file. You can save and link to field binary like this:

def save_excel(self, excel):
     stream = StringIO()
     excel.save(stream)
     encoding_stream = base64.encodestring(stream.getvalue()
     self.write('your_excel':encoding_stream)


And with this you can showing your wizard. 


Avatar
Discard