Python从Excel文件中读取数据

我试图通过循环的Excel文件的行,并写入数据在Web应用程序。 我使用的是一个混合的openpyxl来获取excel数据和pyautogui单击并键入Web应用程序。 但是,当我到达input数据的时候:

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

我得到一个错误“的消息中的c:TypeError:'int'对象是不可迭代的”。 有什么办法可以解决这个问题吗? 这听起来像pyautogui只能input精确的string,而不是从variables读取?

 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) 

谢谢!!

typewrite()需要一个string,所以将c转换为一个string:

 pyautogui.typewrite(str(c)) 

看文档: http : //pyautogui.readthedocs.io/en/latest/keyboard.html