Created
May 3, 2020 13:47
-
-
Save billydh/cdafea2fc8d38833b4cc62d0b1fcca5b to your computer and use it in GitHub Desktop.
Python function to download a Sheet from a Google Spreadsheet into a csv file
This file contains hidden or 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
import csv | |
def download_sheet_to_csv(sheets_instance, spreadsheet_id, sheet_name): | |
result = sheets_instance.spreadsheets().values().get(spreadsheetId=spreadsheet_id, range=sheet_name).execute() | |
output_file = f'{sheet_name}.csv' | |
with open(output_file, 'w') as f: | |
writer = csv.writer(f) | |
writer.writerows(result.get('values')) | |
f.close() | |
print(f'Successfully downloaded {sheet_name}.csv') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment