本文主要是介绍Python实现Excel根据指定区域截图(Windows版本),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
# -*- 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 = Trueexcel.DisplayAlerts = Falseworkbook = excel.Workbooks.Open(filename)worksheet = workbook.Sheets(sheet_name)worksheet.Range(screen_area).CopyPicture()worksheet.Paste()excel.Selection.ShapeRange.Name = pic_nameworksheet.Shapes(pic_name).Copy()img = ImageG
这篇关于Python实现Excel根据指定区域截图(Windows版本)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!