MCPcopy
hub / github.com/burnash/gspread / get_worksheet

Method get_worksheet

gspread/spreadsheet.py:232–254  ·  view source on GitHub ↗

Returns a worksheet with specified `index`. :param index: An index of a worksheet. Indexes start from zero. :type index: int :returns: an instance of :class:`gspread.worksheet.Worksheet`. :raises: :class:`~gspread.exceptions.WorksheetNotFound`: if can't

(self, index: int)

Source from the content-addressed store, hash-verified

230 return self.client.fetch_sheet_metadata(self.id, params=params)
231
232 def get_worksheet(self, index: int) -> Worksheet:
233 """Returns a worksheet with specified `index`.
234
235 :param index: An index of a worksheet. Indexes start from zero.
236 :type index: int
237
238 :returns: an instance of :class:`gspread.worksheet.Worksheet`.
239
240 :raises:
241 :class:`~gspread.exceptions.WorksheetNotFound`: if can't find the worksheet
242
243 Example. To get third worksheet of a spreadsheet:
244
245 >>> sht = client.open('My fancy spreadsheet')
246 >>> worksheet = sht.get_worksheet(2)
247 """
248 sheet_data = self.fetch_sheet_metadata()
249
250 try:
251 properties = sheet_data["sheets"][index]["properties"]
252 return Worksheet(self, properties, self.id, self.client)
253 except (KeyError, IndexError):
254 raise WorksheetNotFound("index {} not found".format(index))
255
256 def get_worksheet_by_id(self, id: Union[str, int]) -> Worksheet:
257 """Returns a worksheet with specified `worksheet id`.

Callers 2

sheet1Method · 0.95
test_get_worksheetMethod · 0.80

Calls 4

fetch_sheet_metadataMethod · 0.95
WorksheetClass · 0.85
WorksheetNotFoundClass · 0.85
formatMethod · 0.80

Tested by 1

test_get_worksheetMethod · 0.64