Skip to content

Instantly share code, notes, and snippets.

@rburhum
Created March 30, 2020 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rburhum/114f1a6cb39a41012233eb49f74231c9 to your computer and use it in GitHub Desktop.
Save rburhum/114f1a6cb39a41012233eb49f74231c9 to your computer and use it in GitHub Desktop.
Download a Google Sheet (or any Google Doc) to Colab VM using gspread
GOOGLE_SPREADSHEET_ID = '<ID_OF_YOUR_SPREADSHEET>' #e.g. 1klG4ihJRyesiWAI_Fq1mv-fErbXtXP4IoVmrJ9hij-k
from google.colab import auth
auth.authenticate_user()
import gspread
from oauth2client.client import GoogleCredentials
gc = gspread.authorize(GoogleCredentials.get_application_default())
import os
if os.path.exists("export.xlsx"):
os.remove("export.xlsx")
# you can change the format changing the 'format' parameter of the URL
exported_file = gc.session.get('https://docs.google.com/spreadsheets/d/' + GOOGLE_SPREADSHEET_ID + '/export?format=xlsx')
open('export.xlsx', 'wb').write(exported_file.content)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment