0

I am referring to below Google Drive api to export Google spreadsheet as CSV. https://developers.google.com/drive/v2/web/manage-downloads

Its working fine But as mentioned in guide it downloads only 1st sheet into csv format. I am looking for a way to download all worksheets into csv format separately. gdata library of python is not working after OAuth1 has has been deprecated. Please suggest if someone has done it successfully in OAuth2.

  • Use the "gid" GET parameter. Maybe these related question might help you: http://stackoverflow.com/questions/11619805/using-the-google-drive-api-to-download-a-spreadsheet-in-csv-format, http://stackoverflow.com/questions/11290337/how-to-convert-google-spreadsheets-worksheet-string-id-to-integer-index-gid – AMS Dec 16 '15 at 09:04

1 Answers1

0

Drive API itself does not offer a way to export a specific worksheet, but with a valid bearer token you can just download it in the desired format via its Google Drive url. The pattern is https://docs.google.com/spreadsheets/d/{{document_id}}/export?format=tsv&gid={{gid}}. The document_id and gid are visiable in the browser URL bar when you open the sheet in Google Drive. Replace tsv with whatever format you need.

I'm not good enough in Python, but I created a demo app in Node.js: git@github.com:joerx/drive-exporter.git. The general flow is:

  • Obtain an access token via the Google APIs OAuth2 flow
  • Figure out sheet_id and gid
  • Construct download url
  • Make a regular HTTP request passing the token as Authorization: Bearer {{token}}

For public sheets you can skip the authorisation part.

General documentation for using Drive API and OAuth2 (with examples in Python) is here

If you need to programmatically determine the gid, this might help: How to convert Google spreadsheet's worksheet string id to integer index (GID)?

Community
  • 1
  • 1
joerx
  • 2,028
  • 1
  • 16
  • 18