Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
body = {
'requests': [{
'duplicateSheet': {
'sourceSheetId': source_sheet_id,
'insertSheetIndex': insert_sheet_index,
'newSheetId': new_sheet_id,
'newSheetName': new_sheet_name
}
}]
}
data = self.batch_update(body)
properties = data['replies'][0]['duplicateSheet']['properties']
worksheet = Worksheet(self, properties)
return worksheet
def worksheets(self):
"""Returns a list of all :class:`worksheets `
in a spreadsheet.
"""
sheet_data = self.fetch_sheet_metadata()
return [Worksheet(self, x['properties']) for x in sheet_data['sheets']]
sheet : str,Worksheet
Name or worksheet to find
Returns
-------
tuple
Tuple like (index, worksheet)
"""
for ix, worksheet in enumerate(self.sheets):
if (
isinstance(sheet, basestring)
and sheet.lower() == worksheet.title.lower()
):
return ix, worksheet
if isinstance(sheet, Worksheet) and sheet.id == worksheet.id:
return ix, worksheet
return None, None
:type index: int
:returns: an instance of :class:`gspread.models.Worksheet`
or `None` if the worksheet is not found.
Example. To get first worksheet of a spreadsheet:
>>> sht = client.open('My fancy spreadsheet')
>>> worksheet = sht.get_worksheet(0)
"""
sheet_data = self.fetch_sheet_metadata()
try:
properties = sheet_data['sheets'][index]['properties']
return Worksheet(self, properties)
except (KeyError, IndexError):
return None
'title': title,
'sheetType': 'GRID',
'gridProperties': {
'rowCount': rows,
'columnCount': cols
}
}
}
}]
}
data = self.batch_update(body)
properties = data['replies'][0]['addSheet']['properties']
worksheet = Worksheet(self, properties)
return worksheet
:returns: an instance of :class:`gspread.models.Worksheet`.
Example. Getting worksheet named 'Annual bonuses'
>>> sht = client.open('Sample one')
>>> worksheet = sht.worksheet('Annual bonuses')
"""
sheet_data = self.fetch_sheet_metadata()
try:
item = finditem(
lambda x: x['properties']['title'] == title,
sheet_data['sheets']
)
return Worksheet(self, item['properties'])
except (StopIteration, KeyError):
raise WorksheetNotFound(title)