Created
April 26, 2021 18:18
-
-
Save dmahely/0c9544dfb68e21aa84e8858f0c9eb555 to your computer and use it in GitHub Desktop.
Download Google sheet in Excel format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This script will take in a Google sheets link | |
# and download the sheet in Excel format to your computer | |
# example: | |
# $ python3 download_sheet.py https://docs.google.com/spreadsheets/d/1eSfTc8B6sU94JVvmXWEyINytWdjzRIwLA8bB93Lycus/edit#gid=1773176508 | |
import sys | |
import webbrowser | |
# read the sheet link argument passed in the cli | |
sheet_link = sys.argv[-1] | |
# prepare query strings | |
gid = sheet_link[sheet_link.find('gid=')::] | |
export_format = 'export?format=xlsx' | |
parameters = export_format + '&' + gid | |
base_link = sheet_link[:sheet_link.find('edit')] | |
# concatenate base link with parameters | |
excel_link = base_link + parameters | |
# open the link in a new tab | |
webbrowser.open_new(excel_link) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment