Python Forum
OpenPyxl: How to iterate through each Column (in 1 row) to find a value?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
OpenPyxl: How to iterate through each Column (in 1 row) to find a value?
#1
When using Python OpenPyxl, how would I iterate through each Column (in only one row) to find a value?

Here's my current (failing) attempt -- (There appears to be an error in (at least) my 2nd for loop.)

book = openpyxl.load_workbook(excelFile)
for sheet in book.worksheets: #For each worksheet
    for colidx in sheet.iter_cols(sheet.min_col,sheet.max_col): #For each Column in a worksheet
        if sheet.cell(1,colidx).value == "ValueImLookingFor": #Search each Column in only Row #1 for value
            print ("Found ValueImLookingFor in COLUMN " + colidx)
ps: Xposted elsewhere last week, but no working answers yet. I'll post the answer to both forums once found.
Thanks so much in advance,
CG
Reply


Messages In This Thread
OpenPyxl: How to iterate through each Column (in 1 row) to find a value? - by chatguy - Jul-26-2020, 05:19 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Find a string from a column of one table in another table visedwings049 8 1,313 Sep-07-2023, 03:22 PM
Last Post: deanhystad
  Openpyxl-change value of cells in column based on value that currently occupies cells phillipaj1391 5 10,170 Mar-30-2022, 11:05 PM
Last Post: Pedroski55
  Find last filled column in openpyxl Irv1n 2 13,181 Jan-16-2022, 11:05 AM
Last Post: Pedroski55
  pandas pivot table: How to find count for each group in Index and Column JaneTan 0 3,434 Oct-23-2021, 04:35 AM
Last Post: JaneTan
  How can I iterate through all cells in a column (with merge cells) with openpyxl? aquerci 1 7,608 Feb-11-2021, 09:31 PM
Last Post: nilamo
  Openpyxl tkinter search a value in Excel column Heathcliff_1 0 3,325 Dec-02-2020, 04:35 PM
Last Post: Heathcliff_1
  Python Openpyxl is unable to check from Column 6 onwards Skye 0 1,779 Oct-13-2020, 06:11 AM
Last Post: Skye
  Using OpenPyXL How To Read Entire Column Into Dictionary jo15765 1 2,750 Jun-08-2020, 04:10 AM
Last Post: buran
  Need to copy column of cell values from one workbook to another with openpyxl curranjohn46 3 11,408 Oct-12-2019, 10:57 PM
Last Post: curranjohn46
  Openpyxl -Coming up with a single column from a multi column data set Givan007 1 2,765 Sep-07-2018, 04:29 AM
Last Post: Prabakaran141

Forum Jump:

User Panel Messages

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