Upload CSV to Google Sheets using gspread
Asked Answered
B

1

5

I have a Json object which needed to be uploaded to the Google Spreadsheet. I have searched and read various resources but could not find the solution. Is there a way to upload object or csv from locally to google spreadsheet using gspread. I will prefer not to use google client api. Thanks

Boom answered 19/10, 2018 at 6:30 Comment(0)
P
3

You can import CSV data using gspread.Client.import_csv method. Here's a quick example from the docs:

import gspread

# Check how to get `credentials`:
# https://github.com/burnash/gspread

gc = gspread.authorize(credentials)

# Read CSV file contents
content = open('file_to_import.csv', 'r').read()

gc.import_csv('<SPREADSHEET_ID>', content)

This will upload your CSV file into the first sheet of a spreadsheet with <SPREADSHEET_ID>.

NOTE

This method removes all other worksheets and then entirely replaces the contents of the first worksheet.

Pukka answered 24/10, 2018 at 17:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.