使用gspread将CSV上载到Google表格 [英] Upload CSV to Google Sheets using gspread
问题描述
我有一个Json对象,需要将其上载到Google Spreadsheet.我已经搜索并阅读了各种资源,但是找不到解决方案.有没有一种方法可以使用gspread将对象或csv从本地上传到Google电子表格.我宁愿不要使用Google客户端api.谢谢
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
推荐答案
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)
这会将您的CSV文件上传到具有 <SPREADSHEET_ID>
.
This will upload your CSV file into the first sheet of a spreadsheet with <SPREADSHEET_ID>
.
注意
此方法删除所有其他工作表,然后完全替换第一个工作表的内容.
This method removes all other worksheets and then entirely replaces the contents of the first worksheet.
这篇关于使用gspread将CSV上载到Google表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!