|
楼主 |
发表于 2023-7-15 06:53
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
最后找了个很笨的办法,用Python模拟键盘算是实现所谓的自动化。据网上说JSA有api,但官方没有公布相关接口文档,估计是会员专用吧以后(但也不至于呀 Crtl+G全选,右键也能批量切换为嵌入单元格图片)!
- import tkinter as tk
- from tkinter import filedialog
- import os
- import time
- import pyautogui
- from pywinauto import application
- def open_wps_file(file_path):
- # 启动WPS Office应用程序
- wps_app = application.Application(backend='uia')
- wps_app.start(r"C:\Program Files (x86)\Kingsoft\WPS Office\11.8.2.11978\office6\et.exe")
- # 等待应用程序完全启动
- time.sleep(3)
- # 发送快捷键,打开文件
- wps_app.top_window().type_keys("^o")
- time.sleep(1)
- # 输入文件路径并确认
- wps_app.top_window().type_keys(file_path)
- time.sleep(1)
- wps_app.top_window().type_keys("{ENTER}")
- time.sleep(1)
- # 定位到对象(B)并选择“定位”
- pyautogui.hotkey('ctrl', 'g')
- time.sleep(1)
- pyautogui.press('b')
- time.sleep(1)
- pyautogui.press('t')
- time.sleep(1)
- pyautogui.press('down')
- time.sleep(1)
- pyautogui.press('right')
- time.sleep(1)
- # 模拟按下Shift键
- pyautogui.keyDown('shift')
- # 模拟按下F10键
- pyautogui.keyDown('f10')
- # 等待一段时间表示按键操作
- time.sleep(0.5)
- # 释放F10键
- pyautogui.keyUp('f10')
- # 释放Shift键
- pyautogui.keyUp('shift')
- time.sleep(1)
- pyautogui.press('r')
- # 模拟按下Ctrl+S键
- pyautogui.hotkey('ctrl', 's')
- def select_file():
- file_path = filedialog.askopenfilename(initialdir="/", title="Select file",
- filetypes=(("Excel files", "*.xlsx"), ("all files", "*.*")))
- # 将路径中的斜杠转换为反斜杠
- file_path = file_path.replace("/", "\")
- if file_path:
- open_wps_file(file_path)
- os.system("taskkill /f /im et.exe")
- # 创建主窗口
- root = tk.Tk()
- # 创建选择文件按钮,注意文件名不能有空格
- select_button = tk.Button(root, text="选择文件", command=select_file)
- select_button.pack()
- # 运行主循环
- root.mainloop()
复制代码 |
|