本帖最后由 yidaiyeer757 于 2022-3-24 15:30 编辑
OA公文处理系统,办公室的收文处理大概都是这么个流程,收文,然后录入收文簿,然后将收文薄传到OA上,本工具是将收文薄的数据直接自动填进oa和WebOffice插件,利用py的selenium进行浏览器操作。from time import sleep
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from PyQt5.Qt import *
import sys
import win32clipboard as wc
import win32con
import openpyxl
import mouse
import pynput
def setCopyTxet(strs): # 设置写入粘贴板函数
wc.OpenClipboard() # 打开粘贴板
wc.EmptyClipboard() # 清空粘贴板
wc.SetClipboardData(win32con.CF_UNICODETEXT, strs) # 写入粘贴板
wc.CloseClipboard() # 关闭粘贴板
chrome_options = Options()
options = webdriver.ChromeOptions()
options.debugger_address = "127.0.0.1:9222"
chrome_options.add_experimental_option("debuggerAddress", "127.0.0.1:9222")
chrome_driver = "C:\Program Files\Google\Chrome\Application\chromedriver.exe" # 指定自己的chromedriver路径
driver = webdriver.Chrome(chrome_driver, chrome_options=chrome_options)
#创建一个应用程序对象
class mywindow(QWidget):
def __init__(self):
'''=========窗口代码开始=========='''
super(mywindow, self).__init__()
self.window=QWidget() #创建窗口对象
self.window.setWindowTitle("") #窗口名字
self.window.resize(200,100) #改变窗口大小
self.window.move(400,200) #移送窗口位置
self.window.setWindowFlags(Qt.WindowStaysOnTopHint)
self.bt()
self.ted()
'''=========窗口代码结束=========='''
self.window.show()
def btevt(self):
if self.tedd.toPlainText() != None:
driver.get("http://36.134.194.224:8098/admin/persion/dispatch/index")
path = "C:\\Users\\Administrator\\Desktop\\2020收文薄2022.1.23备份.xlsx"
sleep(1)
driver.find_elements_by_class_name("layui-admin-iframe")[0].click() # 点击收文处理笺
workbook = openpyxl.load_workbook(path) # 打开表格
shenames = workbook.get_sheet_names() # 获取表格所有子表名
worksheet = workbook.get_sheet_by_name(shenames[0]) # 读取子表
a = worksheet["C" + self.tedd.toPlainText()].value
b = worksheet["d" + self.tedd.toPlainText()].value
c = worksheet["A" + self.tedd.toPlainText()].value
d = self.tedd.toPlainText()
e = worksheet["i" + self.tedd.toPlainText()].value
driver.find_elements_by_class_name("layui-input")[0].click()
driver.find_elements_by_class_name("layui-input")[0].send_keys(a)
driver.find_elements_by_class_name("layui-input")[1].click()
driver.find_elements_by_class_name("layui-input")[1].send_keys(b)
driver.find_elements_by_class_name("layui-input")[2].click()
driver.find_elements_by_class_name("layui-input")[2].send_keys(c)
driver.find_elements_by_class_name("layui-input")[4].click()
driver.find_elements_by_class_name("layui-input")[4].send_keys(d)
driver.find_elements_by_class_name("layui-btn")[0].click()
sleep(1)
'''====鼠标事件===='''
ctr = pynput.mouse.Controller()
mouse.move(766, 190) # 之鼠标位置
ctr.press(pynput.mouse.Button.left) # 按下
ctr.release(pynput.mouse.Button.left) # 弹起
sleep(5)
# mouse.click() #点击
# keyboard.hook(lambda x: print(x)) #匿名函数 调用直接销毁
ctrj = pynput.keyboard.Controller()
'''=====单位======'''
setCopyTxet(a)
mouse.move(520, 509)
ctr.press(pynput.mouse.Button.left)
ctr.release(pynput.mouse.Button.left)
ctrj.press(pynput.keyboard.KeyCode.from_vk(17))
ctrj.press('v')
ctrj.release(pynput.keyboard.KeyCode.from_vk(17))
ctrj.release('v')
sleep(0.2)
'''====文件名======'''
setCopyTxet(b)
mouse.move(660, 660)
ctr.press(pynput.mouse.Button.left)
ctr.release(pynput.mouse.Button.left)
ctrj.press(pynput.keyboard.KeyCode.from_vk(17))
ctrj.press('v')
ctrj.release(pynput.keyboard.KeyCode.from_vk(17))
ctrj.release('v')
sleep(0.2)
'''=====文件号======'''
setCopyTxet(c)
mouse.move(770, 510)
ctr.press(pynput.mouse.Button.left)
ctr.release(pynput.mouse.Button.left)
ctrj.press(pynput.keyboard.KeyCode.from_vk(17))
ctrj.press('v')
ctrj.release(pynput.keyboard.KeyCode.from_vk(17))
ctrj.release('v')
sleep(0.2)
'''=====编号======'''
setCopyTxet(d)
mouse.move(770, 570)
ctr.press(pynput.mouse.Button.left)
ctr.release(pynput.mouse.Button.left)
ctrj.press(pynput.keyboard.KeyCode.from_vk(17))
ctrj.press('v')
ctrj.release(pynput.keyboard.KeyCode.from_vk(17))
ctrj.release('v')
sleep(0.2)
'''=====编号======'''
setCopyTxet(e)
mouse.move(458, 730)
ctr.press(pynput.mouse.Button.left)
ctr.release(pynput.mouse.Button.left)
ctrj.press(pynput.keyboard.KeyCode.from_vk(17))
ctrj.press('v')
ctrj.release(pynput.keyboard.KeyCode.from_vk(17))
ctrj.release('v')
sleep(0.2)
def bt(self):
self.btt=QPushButton(self.window)
self.btt.resize(80, 30)
self.btt.move(60, 60)
self.btt.setText("读取")
self.btt.clicked.connect(self.btevt)
def ted(self):
self.tedd=QTextEdit(self.window)
self.tedd.resize(80, 30)
self.tedd.move(60, 20)
zt = QFont("楷体", 13)
self.tedd.setFont(zt)
if __name__ == '__main__':
app=QApplication(sys.argv)
window=mywindow()
sys.exit(app.exec())
|