Search code examples
pythonexcelopenpyxlpyautogui

Python wriring data from Excel File


I'm attempting to loop through lines of an excel file and write the data in a web application. I'm using a mixture of openpyxl to get the excel data and pyautogui to click and type in the web application. However, when I get to the point to enter the data:

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

I get an error "for c in message: TypeError: 'int' object is not iterable". Is there any way I can get around this? It sounds like pyautogui can only type exact strings, not read from 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)

Thank you!!


Solution

  • typewrite() takes a string, so convert c to a string:

    pyautogui.typewrite(str(c))
    

    See the docs: http://pyautogui.readthedocs.io/en/latest/keyboard.html