使用 xlwt 在 excel 上插入一个 base 64 的图像

Insert an image base 64 on excel using xlwt

你好,我在 odoo 工作,这会将所有图像(如 base64)保存在数据库中。我有代码,但我正在制作一份 excel 报告,我需要在其中放置图像,excel 驱动程序是 xlwt,但我找不到好的方法。

image = product_id.image_smal (this is a base64)

我在网上找到了这个:

xlwt.insert_bitmap('PATH', row, col)

还有这个:

fh = open("imageToSave.png", "wb")
fh.write(imgData.decode('base64'))
fh.close()

我可以保存图像但没有插入并给我这个错误:

bitmap doesn't appear to to be a valid bitmap image.

感谢大家的帮助。

要将 png 转换为 bmp,您需要:

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)

希望对您有所帮助!!