| 我真的是服了,一堆復制黨到處粘貼,也太肆無忌憚了吧,麻煩尊尊下著作權好嗎,好歹這也是我辛辛苦苦寫出來的...... | |
| 原封不動的抄,錯了的也不知道,真的是搞笑! |
1 import os 2 import win32gui, win32api, win32con, win32com 3 from win32com.client import Dispatch 4 from PIL import ImageGrab,Image 5 from time import sleep 6 import pyperclip 7 8 # 呼叫win32api的模擬點擊功能實作ctrl+v粘貼快捷鍵 9 def ctrlV(): 10 win32api.keybd_event(17,0,0,0) #ctrl鍵位碼是17 11 win32api.keybd_event(86,0,0,0) #v鍵位碼是86 12 win32api.keybd_event(86,0,win32con.KEYEVENTF_KEYUP,0) #釋放按鍵 13 win32api.keybd_event(17,0,win32con.KEYEVENTF_KEYUP,0) 14 15 # 呼叫win32api的模擬點擊功能實作alt+s微信發送快捷鍵 (可以根據自己微信發送快捷鍵是什么來進行調整) 16 def altS(): 17 win32api.keybd_event(18, 0, 0, 0) #Alt 18 win32api.keybd_event(83,0,0,0) #s 19 win32api.keybd_event(83,0,win32con.KEYEVENTF_KEYUP,0) #釋放按鍵 20 win32api.keybd_event(18,0,win32con.KEYEVENTF_KEYUP,0) 21 22 # 呼叫win32gui呼叫桌面視窗,獲取指定視窗句柄id,激活視窗 ,向函式傳遞視窗名稱to_weixin 23 def wx_send(to_weixin): 24 for i in range(0,len(to_weixin)): 25 hw = win32gui.FindWindow(None, to_weixin[i]) # 獲取視窗句柄 26 win32gui.GetClassName(hw) # 獲取視窗classname 27 title = win32gui.GetWindowText(hw) # 獲取視窗標題 28 win32gui.GetDlgCtrlID(hw) 29 win32gui.SetForegroundWindow(hw) # 激活視窗 30 sleep(1) 31 ctrlV() 32 sleep(1) 33 altS() 34 35 # 使win32呼叫excel,重繪資料,并發送微信,refreshall重繪excel的所有資料來源,我的資料來源是pq搭建的鏈接資料庫的模型,也可以搭載爬蟲的資料,這樣就可以完成自動重繪資料并發送微信的操作,解放雙手更多的時間來學習 36 def wkb_Operate(class_picture,wkb_path,sleep_time): 37 os.system('taskkill /IM EXCEL.exe /F') 38 xlapp = win32com.client.gencache.EnsureDispatch('Excel.Application') 39 xlapp.Visible = 1 40 xlapp.DisplayAlerts = False # 關閉警告 41 wkb = xlapp.Workbooks.Open(wkb_path) 42 wkb.RefreshAll() 43 sleep(sleep_time) 44 print('檔案【{}】已打開!'.format(wkb_path)) 45 try: 46 for key,vlaue in class_picture.items(): 47 48 to_weixin = class_picture[key]['發送群'] 49 to_sontent = class_picture[key]['發送文本'] 50 sheet_name = class_picture[key]['sheetname'] 51 range_pic = class_picture[key]['圖片區域'] 52 53 pyperclip.copy(to_sontent) 54 wx_send(to_weixin) 55 56 sheet_msg = wkb.Worksheets(sheet_name) 57 sheet_msg.Range(range_pic).CopyPicture() 58 wkb.Worksheets.Add().Name = 'picture' 59 sheet_picture = wkb.Worksheets('picture') 60 sleep(1) 61 sheet_picture.Range('A1').Select() 62 sheet_picture.Paste() 63 sleep(1) 64 xlapp.Selection.ShapeRange.Name = 'pic_name' 65 sheet_picture.Shapes('pic_name').Copy() 66 sleep(1) 67 img = ImageGrab.grabclipboard() 68 sleep(1) 69 wx_send(to_weixin) 70 wkb.Worksheets('picture').Delete() 71 print('#粘貼 成功:%s',sheet_name) 72 except BaseException as e: 73 print(e) 74 pass 75 wkb.Save() 76 wkb.Close(1) 77 xlapp.Quit() 78 print('#更新 成功:%s' % wkb_path) 79 pass 80 # *********************主程式,大致方向是,1、呼叫wkb_Operate重繪函式重繪exce資料,并回傳文本資料播報內容, 81 #2、呼叫wx_send激活微信視窗,3、ctrlV(),altS()模擬粘貼發送功能,4、呼叫excel_picture函式,截圖到剪切板上,并呼叫wx_send(),ctrlV(),altS()微信發送圖片 82 # 微信發送視窗,必須保持一致,按照此名字識別,否則發送不會成功****(抄襲可恥!!作者:故箋)** 83 84 # 檔案路徑: 85 path_process = r"C:\Users\1\Desktop\備份\YTshuaxin\hour\2020年新流水監控表.xlsx" # 檔案夾路徑 86 87 #*********主程式***************# 88 class_picture1 = {'pic1':{'發送群':['管理團隊','資料中心'], 89 'sheetname':'日監控', 90 '圖片區域':'a1:Al50', 91 '發送文本':'截止到目前的流水和PK情況'}} 92 wkb_Operate(class_picture1,path_process,8)
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/158897.html
標籤:Python
上一篇:實體014:分解質因數
下一篇:functools模塊學習
