image in excel report

百般思念 提交于 2020-07-10 00:31:30

问题


Help, How can i print image excel report? Please, help me? I use xlsxwriter. Example of xlsxwriter This is my code:

product_image = product_product.product_tmpl_id.image
imgdata = base64.b64decode(product_image)
image = Image.open(io.BytesIO(imgdata))
# imgdata = base64.b64decode(product_image)
# image =  io.BytesIO(imgdata)
print type(image)
sheet.insert_image(rowx, 12, str(image))

The error is:

warn("Image file '%s' not found." % force_unicode(filename))

How to solve? My goal is print product image in odoo.


回答1:


Something like the following should work:

product_image = product_product.product_tmpl_id.image
imgdata = base64.b64decode(product_image)
image = io.BytesIO(imgdata)

worksheet.insert_image('B5', 'myimage.png', {'image_data': image})

See the insert_image() section of the XlsxWriter docs and this example of inserting images from an io.BytesIO byte stream into a worksheet.



来源:https://stackoverflow.com/questions/52148963/image-in-excel-report

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!