2015-05-11 25 views
2

你好,我在odoo中工作,這將所有的圖像保存在數據庫中的base64上。我有代碼,但我做了一個Excel報告,我需要把圖像,Excel驅動程序是xlwt,但我找不到一個不錯的方法。使用xlwt在excel中插入一個圖像庫64

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. 

謝謝你的幫助。

回答

1

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

希望這有助於!