Python 从 Excel 文件写入数据

Python wriring data from Excel File

我正在尝试遍历 excel 文件的行并将数据写入 Web 应用程序。我混合使用 openpyxl 来获取 excel 数据和 pyautogui 来单击并输入 Web 应用程序。然而,当我到了要输入数据的时候:

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

我收到一个错误 "for c in message: TypeError: 'int' object is not iterable"。有什么办法可以解决这个问题吗?听起来 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)

谢谢!!

typewrite() 接受一个字符串,所以将 c 转换为字符串:

pyautogui.typewrite(str(c))

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