使用xlwt在Excel上插入图像库64 [英] Insert an image base 64 on excel using xlwt
本文介绍了使用xlwt在Excel上插入图像库64的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我正在odoo中工作,这会将所有图像(例如base64)保存在数据库中.我有代码,但是我正在制作一个Excel报告,需要在其中放置图像,Excel驱动程序是xlwt,但是我找不到很好的方法.
Hello i am workin in odoo and this save all the images like base64 on the database. I have the code, but I am making an excel report where I need to put the image, the excel driver is xlwt, but i can't find a nice method.
image = product_id.image_smal (this is a base64)
在网络上,我发现了这一点
On the web i found this:
xlwt.insert_bitmap('PATH', row, col)
和这个:
fh = open("imageToSave.png", "wb")
fh.write(imgData.decode('base64'))
fh.close()
我可以保存图像但没有插入图像,并给我这个错误:
I can save the image but is not inserted and give me this error:
bitmap doesn't appear to to be a valid bitmap image.
谢谢您的帮助.
推荐答案
要将png转换为bmp,您需要:
to convert png to bmp you need to:
from PIL import Image
img = Image.open("imageToSave.png")
r, g, b, a = img.split()
img = Image.merge("RGB", (r, g, b))
img.save('imagetoadd.bmp')
xlwt.insert_bitmap('imagetoadd.bmp', row, col)
希望得到帮助!
这篇关于使用xlwt在Excel上插入图像库64的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文