Skip to content

Instantly share code, notes, and snippets.

@billydh
Created May 3, 2020 13:47
Show Gist options
  • Save billydh/cdafea2fc8d38833b4cc62d0b1fcca5b to your computer and use it in GitHub Desktop.
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
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