这是我从网络上的两个不同链接中找到的,对我来说效果很好。Matplotlib允许保存png文件,这是我在这里使用的:
from PIL import Imagefile_in = "image.png"img = Image.open(file_in)file_out = 'test1.bmp'print len(img.split()) # testif len(img.split()) == 4: # prevent IOError: cannot write mode RGBA as BMP r, g, b, a = img.split() img = Image.merge("RGB", (r, g, b)) img.save(file_out)else: img.save(file_out)from xlwt import Workbookw = Workbook()ws = w.add_sheet('Image')ws.insert_bitmap(file_out, 0, 0)w.save('images.xls')该代码的图像部分来自Ene Urans的响应,网址为http://www.daniweb.com/software-
development/python/threads/253957/converting-an-image-file-png-to-a-bitmap-
file。
xlwt只是我在http://www.simplistix.co.uk/presentations/python-
excel.pdf上找到的xlwt的文档形式。



