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
  Copy column from one existing excel file to another file mkujawsk 0 329 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 4,595 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 368 Mar-24-2021, 04:56 AM
Last Post: shantanu97
  How to append a value to specific excel cell using openpyxl hobbyist 0 592 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 986 Feb-11-2021, 09:31 PM
Last Post: nilamo
  Text to Column to Excel in Python giddyhead 0 329 Feb-09-2021, 03:18 AM
Last Post: giddyhead
  Append excel sheet using openpyxl TammyP 1 400 Feb-02-2021, 06:32 PM
Last Post: nilamo
  Python Openpyxl is unable to check from Column 6 onwards Skye 0 261 Oct-13-2020, 06:11 AM
Last Post: Skye
  Openpyxl: Excel formula & condition formatting removed JaneTan 0 607 Sep-25-2020, 07:02 AM
Last Post: JaneTan
  String search in different excel Kristenl2784 0 437 Jul-20-2020, 02:37 PM
Last Post: Kristenl2784

Forum Jump:

User Panel Messages

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