Upload CSV to Google Sheets using gspread

半城伤御伤魂 提交于 2020-01-04 02:35:50

问题


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


回答1:


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>.



来源:https://stackoverflow.com/questions/52886926/upload-csv-to-google-sheets-using-gspread

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!