0

I would like to retrieve data of spreadsheet by searching for the spreadsheet by name. I wonder how it works?

result = service.spreadsheets().values().get(title=spreadsheetTitle, range=rangeName).execute()
Tadhg McDonald-Jensen
  • 20,699
  • 5
  • 35
  • 59
tc2013
  • 59
  • 1
  • 9

2 Answers2

0

From this example, you can open a spreadsheet by its title or url.

Example:

def open(self, title):
        """Opens a spreadsheet, returning a :class:`~gspread.Spreadsheet` instance.
        :param title: A title of a spreadsheet.
        If there's more than one spreadsheet with same title the first one
        will be opened.
        :raises gspread.SpreadsheetNotFound: if no spreadsheet with
                                             specified `title` is found.
        >>> c = gspread.Client(auth=('user@example.com', 'qwertypassword'))
        >>> c.login()
        >>> c.open('My fancy spreadsheet')
        """
        feed = self.get_spreadsheets_feed()

        for elem in feed.findall(_ns('entry')):
            elem_title = elem.find(_ns('title')).text
            if elem_title.strip() == title:
                return Spreadsheet(self, elem)
        else:
            raise SpreadsheetNotFound

You can also check these links:

Community
  • 1
  • 1
abielita
  • 13,147
  • 2
  • 17
  • 59
0

You can use pygsheets, a python library for google sheets api v4.

import pygsheets

gc = pygsheets.authorize()

# Open spreadsheet by title
sh = gc.open('my new ssheet')
Nithin
  • 5,470
  • 37
  • 44