pyautogui未在文本字段中写入Excel单元格内容

问题描述 投票:0回答:1

我正在尝试使用pyautogui模块将Excel xlsx文件中的数据写入软件的文本字段中。运行代码后,我打开软件窗口以输入数据。不幸的是,代码没有在字段中写入数据。如果我为打开的记事本窗口运行此代码,则它可以工作。

""" Importing Pesticides list into Manabh Softwarer"""
import time
import xlrd
import pyautogui as gui

# Excel file location    
loc = ("D:\import.xlsx")

wb = xlrd.open_workbook(loc) 
sheet = wb.sheet_by_index(0) # Opens Sheet1 

time.sleep(10) # Delay to manually open Manabh data entry window
row = sheet.nrows+1
col = sheet.ncols
print('Columns:',col)
print('Rows:',row)

for i in range(1,row,1):
    j = 0
    val = sheet.cell_value(i, j)
    gui.write(val ,0.01 ) # Item name
    time.sleep(0.01)
    gui.press('tab')
    j += 1
    gui.write(sheet.cell_value(i, j),0.01 ) # Manufacturer
    time.sleep(0.01)

脚注:

  1. 具有管理权限的Windows 8.1。
  2. 'Manabh Software'窗口,具有管理特权。
  3. Here is link to Screenshot of 'Manabh Software Text Entry' window
python-3.x xlrd pyautogui
1个回答
0
投票

在Reddit论坛上找到的解决方案,用户正在游戏中遇到similar problem。py文件需要以提升的(管理员)权限运行。我通过右键单击“开始”菜单中的“ IDLE”快捷方式并选择“以管理员身份运行”来运行它。然后从文件菜单打开py文件,然后通过功能键“ F5”运行它。

© www.soinside.com 2019 - 2024. All rights reserved.