python可以给excel编程吗_python – 我可以通过编程方式将matplotlib图形插入Excel吗?...
我將matplotlib文件保存為.tiff圖像.我希望能夠打開一個excel文件并將圖像粘貼到那里.
openpyxl似乎不支持圖像嵌入. xlwt確實只有bmp.
或者,如果我可以通過編程方式將tiff轉換為bmp,那也可能有所幫助.
我們歡迎任何一個想法.
如同
但是,從tiff到bmp的轉換是可以接受的,因為我的圖表量很小(每個文件大約10個).
解決方法:
這是我從網絡上的兩個不同鏈接中找到的,這對我來說非常有效. Matplotlib允許保存png文件,這是我在這里使用的:
from PIL import Image
file_in = "image.png"
img = Image.open(file_in)
file_out = 'test1.bmp'
print len(img.split()) # test
if 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 Workbook
w = Workbook()
ws = w.add_sheet('Image')
ws.insert_bitmap(file_out, 0, 0)
w.save('images.xls')
標簽:python,matplotlib,excel
來源: https://codeday.me/bug/20191001/1838664.html
總結
以上是生活随笔為你收集整理的python可以给excel编程吗_python – 我可以通过编程方式将matplotlib图形插入Excel吗?...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: pythontkinter控件单选框怎么
- 下一篇: python 手动读取cifar10_P