import os标签:pyautogui,表格,Python,app,Excel,bk,sleep,time From: https://www.cnblogs.com/yiblue/p/16721297.html
import time
import pyautogui
import win32com.client as win32
# 发送函数
def fz(app,bk):
x, y = pyautogui.size()
time.sleep(1)
app.Application.Run("复制图1")
time.sleep(1)
pyautogui.hotkey('ctrl', 'v')
pyautogui.press('enter')
time.sleep(1)
pyautogui.click(395, 880)
pyautogui.moveTo(x / 2, y / 2)
# 保存记录到文件夹
app.Application.Run("另存1")
time.sleep(2)
bk.Save()
bk.Close()
app.Quit()
# 函数五 //定义定位报错处理函数
def ft(app,bk):
try:
pyautogui.click(1099, 319)
fz(app,bk)
except:
try:
pyautogui.click(1099, 319)
fz()
except:
bk.Save()
bk.Close()
app.Quit()
def send():
# 定义文件路径
filepath = os.path.dirname(__file__) + '\组板产能1.xlsm'
print('打开Excel中。。')
app = win32.gencache.EnsureDispatch("Excel.Application")
# app.Visible = True
print('打开。。')
bk = app.Workbooks.Open(filepath)
print('打开后..')
ft(app,bk)