Odoo Help


Add Signature Image (stored in database) to excel file

PujaBaa Zala
on 9/25/15, 6:34 AM 1,219 views


I've created xls report from wizard.Now I want to add my signature image of parent company that is stored in database. I've tried below code , but I get output as a string for that field instead of Image.I've already checked resources from net to include image using Workbook, but didn't really much helpful as needed.


def print_bank_report(self, cr, uid, ids, context=None):
employee_obj = self.pool.get('hr.employee')
payslip_obj = self.pool.get('hr.payslip')
payslip_line_obj = self.pool.get('hr.payslip.line')

amount = 0.0
total_amount = 0.0
total_employee = employee_obj.search(cr,uid,[('company_id','=',wiz_obj.company_id.id)],context=context)
total_payslip = payslip_obj.search(cr,uid,[('date_from','=',wiz_obj.from_date),('date_to','=',wiz_obj.to_date)],context=context)

sig = wiz_obj.company_id.parent_id.signature_image  

res1 = []
res2 = []
for employee in employee_obj.browse(cr, uid, total_employee, context=context):
for payslip in payslip_obj.browse(cr, uid, total_payslip, context=context):
if employee.id == payslip.employee_id.id:
if employee.bank_name.name == 'SBOP':
print employee.bank_name.name
total_lines = payslip_line_obj.search(cr,uid,[('slip_id','=',payslip.id),('code','=','NET')])
for lines in payslip_line_obj.browse(cr,uid,total_lines):
amount = lines.amount
total_amount += lines.amount
if employee.bank_name.name == 'SBOP':
res1.append ({
'remark': employee.company_id.name,
'ifsc_code': employee.ifsc_code,


Here, In .py file, I've created 'res1' then added successfully this into worksheet using workbook = xlwt.Workbook().

In output of sig field, I got too long String in .xls file. How can I get image in .xls file? Or suggest me different possibilities to decode this string into other image format?!


Axel Mendoza

--Axel Mendoza--
| 7 7 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full time employee trying to understand what to do an how

Reach me at aekroft@gmail.com

Axel Mendoza
On 9/25/15, 8:48 AM

Hi @PujaBaa Zala

From what I know from trying to do the same you have 2 choices here:

1- You could always store the image data in a temp file in order to be used in your xlwt code.

2- You can use openpyxl as the report excel generator, I successfully done what you need only with that library. I used specifically 1.7.0, I don't know if latter versions remove that feature.


Example of using openpyxl with an in-memory image data

from openpyxl import Workbook
from openpyxl.writer.excel import ExcelWriter
from openpyxl.drawing import Image

from PIL import Image as PILImage
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO

wb = Workbook()
ws = wb.get_active_sheet()

#extra has the data of the image from the database
im = PILImage.open(StringIO(extra))
img = Image(im)

handler = StringIO()
writer = ExcelWriter(wb)
xls = handler.getvalue()

Hello @Axel Mendoza , Thanx for suggesting openpyxl ! I've read about Inserting an image using openpyxl, But How can I use it to add image that is stored in database. can you pls help me how to use it?

PujaBaa Zala
on 9/26/15, 1:13 AM

I edited my answer to include an example

Axel Mendoza
on 9/26/15, 1:48 AM

@Axel Mendoza : thanx a lot. I'll check it

PujaBaa Zala
on 9/26/15, 5:59 AM

could you accept the answer on the check mark?

Axel Mendoza
on 12/23/15, 2:41 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

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

Question tools

2 follower(s)


Asked: 9/25/15, 6:34 AM
Seen: 1219 times
Last updated: 5/31/16, 8:31 AM