import win32com.client
from PIL import ImageGrab
import os
o = win32com.client.Dispatch("Excel.Application")
o.Visible = 0
o.DisplayAlerts = 0
wb = o.Workbooks.Open(srcfile)
for sheet in wb:
for n, shape in enumerate(sheet.Shapes):
shape.Copy()
image = ImageGrab.grabclipboard()
image.save(file_path,'png') # 一般这段代码容易出错,因为剪切板可能没有内容,最好加上try...except...
pass
pass
wb.Close(True)
o.Quit()