8

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.

klarow
  • 81
  • 1
  • 2

2 Answers2

1

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.

1

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)
jxck
  • 26
  • 2
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 28 '22 at 00:12