How can I get a list of sheets (name and "gid") in a Google spreadsheet using the Drive API?
Indeed this seems to be a duplicate of How to convert Google spreadsheet's worksheet string id to integer index (GID)?
Here is the quick answer:
def to_gid(worksheet_id): return int(worksheet_id, 36) ^ 31578
You can do this using the Spreadsheet service in Google Apps Script. It's not as convenient as having a direct API call, but at least it is possible:
- Call the
SpreadsheetApp.openById(id)
method to open the spreadsheet using the Drivefile_id
. - Call the
Spreadsheet.getSheets()
method to retrieve a list ofSheet
objects. - For each sheet, call the
Sheet.getSheetId()
andSheet.getSheetName()
methods to get the name (which is what the spreadsheet user sees) and the sheetId (which is what needs to be provided in thegid=
parameter when exporting).
You can use the recently-announced Apps Script Execution API
to provide a REST API for your Apps Script project, which you can then call in a similar manner to the Drive API.