Python Forum
Openpyxl tkinter search a value in Excel column
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Openpyxl tkinter search a value in Excel column
#1
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;
Larz60+ write Dec-02-2020, 06:44 PM:
The tag you should use for multi-line python srcipt is '[python]',
non '[inline]'. I fixed this.
inline is used for a single python statement embedded within a text field.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Find last filled column in openpyxl Irv1n 2 175 Jan-16-2022, 11:05 AM
Last Post: Pedroski55
  Trying to search and make new column from the keyword. dgarg 1 197 Dec-20-2021, 08:41 PM
Last Post: deanhystad
  Want to remove the text from a particular column in excel shantanu97 2 745 Jul-05-2021, 05:42 PM
Last Post: eddywinch82
  Copy column from one existing excel file to another file mkujawsk 0 1,034 Apr-14-2021, 06:33 PM
Last Post: mkujawsk
  OpenPyxl: How to iterate through each Column (in 1 row) to find a value? chatguy 2 9,318 Apr-06-2021, 04:52 AM
Last Post: carlhyde
  Add a new column when I extract each sheet in an Excel workbook as a new csv file shantanu97 0 947 Mar-24-2021, 04:56 AM
Last Post: shantanu97
  How to append a value to specific excel cell using openpyxl hobbyist 0 2,055 Mar-05-2021, 07:14 PM
Last Post: hobbyist
  How can I iterate through all cells in a column (with merge cells) with openpyxl? aquerci 1 3,101 Feb-11-2021, 09:31 PM
Last Post: nilamo
  Text to Column to Excel in Python giddyhead 0 771 Feb-09-2021, 03:18 AM
Last Post: giddyhead
  Append excel sheet using openpyxl TammyP 1 906 Feb-02-2021, 06:32 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020