Odoo Help

1 Answer
Haresh Kansara
3/19/19, 2:12 PM

Hello Ajini,

i am not perfectly able to help you, but i can help you how to create XLS report in odoo and set into binary field that you can download. Just follow bellow step.

# import packages required for writing XLS data

from io import BytesIO

import xlwt,  base64

# Define one field that temporary hold data for download

file = fields.Binary('XLS File', readonly=True)

# Do bellow stuff in onchange / method or button click function to write XLS  

# set sheet name and format

FP = BytesIO()

WB = xlwt.Workbook(encoding='utf-8')

writer = WB.add_sheet('Sheet Name')

row = 1

col = 0

header_cols = 4

# Set sheet first row (for header purpuse)  

writer.write_merge(row, row, 0, header_cols, "Contacts information", "you can apply css style here for fiest column like: height: 200px;")

row += 1

# write data (for column title)

writer.write(row, col + 1, "Name", "font-weight:bold;")

writer.write(row, col + 2, "Email", "font-weight:bold;")

writer.write(row, col + 3, "Phone", "font-weight:bold;")

row += 1

col = 0

# Set data

writer.write(row, col + 1, "A", "font-weight:normal;")

writer.write(row, col + 2, "B", "font-weight:normal;")

writer.write(row, col + 3, "C", "font-weight:normal;")


# set file to binary field

self.file = base64.encodestring(FP.getvalue())

Hope it will help you to do what you want.
I think you have to add this code to loop for printing One2many data.

Accept and upvote answer if helpful

Thanks and regards 
Haresh Kansara
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.

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now