Skip to content

Instantly share code, notes, and snippets.

@mithunkamat
Created May 18, 2020 07:10
Show Gist options
  • Save mithunkamat/11f62771198e96d8a5d13dd577c4f558 to your computer and use it in GitHub Desktop.
Save mithunkamat/11f62771198e96d8a5d13dd577c4f558 to your computer and use it in GitHub Desktop.
Searching a column with openpyxl.
# define function to search a given column in an openpyxl worksheet object
def search_col(sheet, column, value, limit=100):
# loop through each row upto the limit, beginning from 1
for row in range(1, limit+1):
if sheet[f"column{row}"].value == value:
# if we find the value we are searching for, return col + row
return (col, row)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment