Thank you all for your generous help. I am still new to programming and I have some trouble automating data entry from Excel sheet to a third-party software.
For the excel sheet, it is very straight forward with 3 columns:
ROW1 Item ID | Customer Name | Order ID
ROW2 0872 | Hello | 89182
ROW3 0981 | World | 78192
………..
What I need to do is go into the software, search by item ID, and add the order ID under a very specific section.
Since the vendor does not give me the back end access, I decided to use pyautogui to automate clicking and data entry.
To prevent python from reading the first row and go indefinitely, I defined:
start_row = 2
end_row = 2000 # Hypothetical end
However, it only processes the 2000th row by skipping 1-1999th rows.
It only works when I run the code for single line as:
start_row = 2
end_row = 2
And it processes Row 2
Below is my code:
import pyautogui
import time
import openpyxl
import keyboard
# currentMouseX, currentMouseY = pyautogui.position()
# print(currentMouseX, currentMouseY) # To find mouse cordinates for desired fields + Buttons
# Grab the data from the Excel workbook
file_path="D:/User/Documents/Order ID Edit/Recent_Transactions.xlsx"
workbook = openpyxl.load_workbook (file_path)
wsheet = workbook.active
start_row = 2
end_row = 2000
pyautogui.click (806,747) # Software icon on taskbar, I need to log in and go to logistic section, but it only needs me to do it once so I didn't automate this.
# Inside the software:
# To Search
pyautogui.click(305,59) # Click search icon
pyautogui.doubleClick(301,95) # Click box for search
# Grab Item ID from Excel in certain range:
for i in range(start_row, end_row + 1):
j = 1
ItemID = wsheet.cell(row=i, column=j).value
pyautogui.write(ItemID)
keyboard.send('Enter')
# Edit Order ID:
pyautogui.doubleClick (357,560) #Click on Order ID
for i in range(start_row, end_row + 1):
j = 3
OrderID = wsheet.cell(row=i, column=j).value
pyautogui.write(OrderID)
keyboard.send('Enter')
# Save all edits:
pyautogui.click(355,64) # Click Edit Icon
pyautogui.click(371,64) # Click Save Icon
Robert Jin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.