excel报告中的图像

问题描述 投票:0回答:2

帮助,我如何打印图像excel报告?请帮我?我用的是xlsxwriter。 Example of xlsxwriter这是我的代码:

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))

错误是:

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

怎么解决?我的目标是在odoo中打印产品图像。

image report odoo xlsx
2个回答
2
投票

像下面这样的东西应该工作:

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})

请参阅XlsxWriter文档的insert_image()部分以及将example字节流中的图像插入工作表的io.BytesIO


© www.soinside.com 2019 - 2024. All rights reserved.