从Excel文件中获取Python的数据

问题描述:

我正在尝试循环访问excel文件的行并将数据写入Web应用程序。我使用openpyxl的混合体来获取excel数据和pyautogui来单击并键入Web应用程序。然而,当我去点输入数据:从Excel文件中获取Python的数据

c=Sheet.cell(row=i,column=7).value 
    pyautogui.typewrite(c) 

我得到一个错误“在消息C:类型错误:‘诠释’对象不是可迭代”。有什么方法可以解决这个问题吗?这听起来像pyautogui只能输入精确的字符串,而不是从变量读取?

import openpyxl 
import pyautogui 
import time 
wb = openpyxl.load_workbook('H:\\Python Transfer.xlsx') 
type (wb) 
wb.get_sheet_names() 
Sheet = wb.get_sheet_by_name('Sheet1') 
lastRow = Sheet.max_row 
for i in range(2,lastRow + 1): 
    #print(Sheet.cell(row=i,column=7).value) 
    pyautogui.click(1356,134) 
    time.sleep(5) 
    c=Sheet.cell(row=i,column=7).value 
    pyautogui.typewrite(c) 
    time.sleep(2) 
    pyautogui.click(1528,135) 

谢谢!

+2

我认为pyaugogui发出按键每次一个字符(或钥匙),所以也许尝试将c转换为一个字符串; pyautogui.typewrite(str(c)) – LeopoldVonBuschLight

+0

谢谢!这工作! – MCJNY1992

typewrite()需要一个字符串,所以转换C到字符串:

pyautogui.typewrite(str(c)) 

请参阅该文档: http://pyautogui.readthedocs.io/en/latest/keyboard.html