gspread findall() only within 1 column
Asked Answered
C

2

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.

Contraction answered 29/2, 2016 at 22:50 Comment(0)
L
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.

Liquefy answered 7/10, 2016 at 20:48 Comment(0)
T
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)
Tripitaka answered 27/5, 2022 at 14:16 Comment(1)
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.Myth

© 2022 - 2024 — McMap. All rights reserved.