使用gspread将CSV上传到Google Sheets

4

我有一个Json对象需要上传到Google表格中。我已经搜索并阅读了各种资源,但没有找到解决方案。是否有一种方法可以使用gspread从本地上传对象或csv到Google表格?我更喜欢不使用Google客户端API。谢谢。

1个回答

3
您可以使用 gspread.Client.import_csv 方法导入 CSV 数据。以下是文档中的一个快速示例:
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>的电子表格的第一个工作表中。
注意:
此方法将删除所有其他工作表,然后完全替换第一个工作表的内容。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接