Python Forum
Openpyxl tkinter search a value in Excel column - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Openpyxl tkinter search a value in Excel column (/thread-31288.html)



Openpyxl tkinter search a value in Excel column - Heathcliff_1 - Dec-02-2020

Hello,

I am a big beginner in Python, so I hope I will fine a help to resolve my current problem.
Firstly, I am working with Python 3, and I want when the user enter a site ID (format Txxxxx) in ZT1, the program goes to Excel file "My_Excel.xlsx" and search for the site ID in the column "B", and if this value is found, the program should return the value of the Col "I" in ZT2 (of the first row where site ID in Col "B" is found). Kind of Vlookup function.
This is my code to complete:
from tkinter import *
from tkinter import messagebox
import openpyxl
from openpyxl import Workbook
 
def Verification(*args):
   value = ZT1.get()
   if len(value) != 6 or value[:1] != "T" or not value[1:6].isdigit() :
     messagebox.showwarning("Error", "ID not valide")
     ZT1.delete(0,END)
   else :
 
# Put the value of Col "I" in ZT2 (if the ID is found in Col "B" of course)
 
fen = Tk()
fen.state('zoomed')
fen.title('Rapports CCU')
Label1 = Label(fen, text = "N° ID :", font = 'times')
Label1.place(x = 35,y = 16)
 
Label2 = Label(fen, text = "Region :", font = 'times')
Label2.place(x = 268,y = 16)
 
 
ZT1 = Entry(fen, width = 17, justify='center', bg="#aee6ff")
ZT1.place(x = 155, y = 20)
ZT1.bind("<Return>",Verification)
 
ZT2 = Text(fen, width = 13, height=1, bg="#c9d4ff")
ZT2.place(x = 405, y = 20)
ZT2.config (state=DISABLED)
 
wb = openpyxl.load_workbook('My_Excel.xlsx')
ws = wb.active
 
fen.mainloop()
Thanks in advance.

Ragards;