i have an excel sheet and i want to check if particular value is there
the code is
import openpyxl
book = openpyxl.load_workbook("C:\\Users\\abdul_saboor\\PycharmProjects\\sleneiumpythonsession\\venv\\LoginData.xlsx")
first_sheet = book.get_sheet_by_name('Sheet1')
particular_cell_value = first_sheet.rows
particular_cell_value1 = first_sheet.columns
for x in particular_cell_value:
for j in particular_cell_value1:
if "[email protected]" in particular_cell_value1:
print("Test case passed")
else:
print("Failed")
but the output is displaying failed everytime? i want to check if [email protected] is there or not.Can anyone help?
CodePudding user response:
Use pandas
:
import pandas as pd
df = pd.read_excel('LoginData.xlsx')
isin = '[email protected]' in df['username'].tolist()
print(f"User [email protected] is in file: {'yes' if isin else 'no'}")