# -*- coding:utf-8 -*-
__author__ = 'yangxin_ryan'
from win32com.client import Dispatch, DispatchEx
import pythoncom
from PIL import ImageGrab
"""
对excel的表格区域进行截图——用例:
excel_catch_screen(u"D:\Desktop\到期预测日报 20190521.xlsx", u"到期预测日报", u"到期预测日报", "A1:O96")
"""
class ExcelToImageWindow(object):
def excel_catch_screen(self, filename, sheet_name, screen_area, pic_name, img_name=False):
pythoncom.CoInitialize()
excel = DispatchEx("Excel.Application")
excel.Visible = True
excel.DisplayAlerts = False
workbook = excel.Workbooks.Open(filename)
worksheet = workbook.Sheets(sheet_name)
worksheet.Range(screen_area).CopyPicture()
worksheet.Paste()
excel.Selection.ShapeRange.Name = pic_name
worksheet.Shapes(pic_name).Copy()
img = ImageG