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


Messages In This Thread
Openpyxl tkinter search a value in Excel column - by Heathcliff_1 - Dec-02-2020, 04:35 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Search Excel File with a list of values huzzug 4 1,216 Nov-03-2023, 05:35 PM
Last Post: huzzug
  Excel Automation using Openpyxl pradyumnajpn 1 804 May-16-2023, 09:38 AM
Last Post: Larz60+
  Openpyxl manipulate excel write formula SamLiu 0 1,050 Nov-04-2022, 03:00 PM
Last Post: SamLiu
  How to format Excel column with comma? dee 0 1,360 Jun-13-2022, 10:11 PM
Last Post: dee
  Python, Tkinter, & Excel Extra 2 1,613 Apr-29-2022, 10:42 PM
Last Post: Extra
  Openpyxl-change value of cells in column based on value that currently occupies cells phillipaj1391 5 9,789 Mar-30-2022, 11:05 PM
Last Post: Pedroski55
  Appending Excel column value as CSV file name sh1704 0 1,295 Feb-06-2022, 10:32 PM
Last Post: sh1704
  Find last filled column in openpyxl Irv1n 2 12,753 Jan-16-2022, 11:05 AM
Last Post: Pedroski55
  Trying to search and make new column from the keyword. dgarg 1 1,480 Dec-20-2021, 08:41 PM
Last Post: deanhystad
  Want to remove the text from a particular column in excel shantanu97 2 2,139 Jul-05-2021, 05:42 PM
Last Post: eddywinch82

Forum Jump:

User Panel Messages

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