简体   繁体   中英

I want to be able to locate a value in excel from python and print the value in the next column

I am trying to be able to let a user give me a value in python and then the code finds the value in an excel document and prints the value from the next column.

I can't seem to find any code for it and i am struggling to write it myself, here is my code so far:

 dotill = input("would you like to enter till mode?")
 if dotill == "yes":
     barcode = input("please start scanning")
     find (bardcode) in:
         excel_document = openpyxl.load_workbook('scanza.xlsx',data_only=True)
          heet = excel_document['completetransaction'] 

Can anyone help?

You might want to have a look into the pandas package. It provides an interface with excel.

A part of your question could than be solved using a pandas DataFrame from your excel file that with the path PATH/TO/WORKSHEET beeing searched for the value TESTVALUE which are to replaced in the example below:

import pandas as pd

df = pd.read_excel(PATH/TO/WORKSHEET)

if TESTVALUE in df.values:
    print('Value in sheet!')
else:
    print('Value not in sheet!')

pd.read_excel(path) generates a DataFrame from an excel file. df.values gets you an array of the values. The if statement checks for your value within the array.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM