I am trying to find the cell locations of specific IDs within the first column of a google spreadsheet using gspread.
Is there a way to search only within the first column, and not the entire spreadsheet?
I have been using: gspread.Worksheet(example).findall(query)
but searching through each cell is time-consuming.
You can use the Worksheet.range() function to help you do this:
query = "findme"
worksheet = worksheet_object
first_column = worksheet.range("A1:A{}".format(worksheet.row_count)
found_cell_list = [found for found in first_column if found.value == query]
I'm making the assumption that your first column is column "A" but if not just build your own range string with the appropriate column letter or use Worksheet.get_addr_int().
This gives you a list of cells which you can use to do what you need to. Though I'm not sure if the performance will be much better on very large sheets.
You can use the in_column argument:
import gspread
auth = gspread.oauth()
gsheet = auth.open("Example spreadsheet").get_worksheet(0)
matching_cells = gsheet.findall(query='query', in_column=1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With