1 year ago
#387950
Chris
Python if statement works with one excel file but not another
I am writing a code to automate some data entry from an excel file into a website. I've already tested out the code and it works with no issues using an unencrypted file. The issue appears when I run the code again with an identical copy of the excel file, except this one is encrypted. There is no other differences between the two files yet the code only works for the unencrypted file.
Here is a sample of the code I was using:
import pandas as pd
import pyautogui as pya
import xlwings as xw
# Path for encrypted file
PATH = 'D:\filename.xlsx'
wb = xw.Book(PATH, password=pword)
sheet = wb.sheets['sheetname']
df = sheet.used_range.options(pd.DataFrame, index=False, header=True).value
df.head()
if (df['columnname'][row] == healthnum and df['columnname2'][row] == 5):
pya.hotkey ('5')
elif df['columnname'][row] == healthnum and df['columnname2'][row] == 4.4:
pya.hotkey ('4')
elif df['columnname'][row] == healthnum and df['columnname2'][row] == 3.4:
pya.hotkey ('3')
elif df['columnname'][row] == healthnum and df['columnname2'][row] == 2:
pya.hotkey ('2')
elif df['columnname'][row] == healthnum and df['columnname2'][row] == 1:
pya.hotkey ('1')
pya.hotkey('tab')
It should be pressing '4' if run with no issues but it does not press anything and tabs to the next section I can't seem the find the issue since both files have identical data but the code only works for one. There are no errors that appear when I run it either.
Appreciate any help!
python
excel
pandas
pyautogui
0 Answers
Your Answer