如何使用Google Sheets API V4导入CSV文件 [英] How to import a CSV file using Google Sheets API V4

查看:63
本文介绍了如何使用Google Sheets API V4导入CSV文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Python 2.7脚本,该脚本分析SQL表中的数据,最后生成一个CSV文件.

I'm developing a Python 2.7 script that analyzes data from an SQL table and at the end, generates a CSV file.

生成文件后,我将登录到我的Google工作表帐户,并使用导入选项将CSV文件导入到Google电子表格中

Once the file is generated, I'm logging into my google sheet account and use the import option to import my CSV file into the google spreadsheet

体力劳动有点愚蠢,我希望将此功能添加到脚本中.

The manual labor is kinda stupid and I wish to add this ability to my script.

因此,我按照本指南 Python快速入门并能够完成所有步骤.

So, I followed this guide, Python Quickstart and was able to complete all the steps.

然后我关注了 Google Sheets API参考,并调查了方法:sheets.create .如果我理解正确,它不提供从文件导入的选项.

Then I followed Google Sheets API reference and looked into Method: spreadsheets.create. If I understand correctly, it does not provides the options to import from a file.

似乎没有用于导入功能的API.

It seems like there is no API for the import functionality.

如何使用Google Sheets API V4导入CSV文件?是他们所缺少的示例/参考吗?

How to import a CSV file using Google Sheets API V4? Is their an example/reference that I'm missing?

推荐答案

Sam Berlin答案的另一种选择.如果您使用的是Python,则可以通过 gspread 使用Drive API导入CSV文件.这是一个示例:

Another alternative to Sam Berlin's answer. If you're using Python, you can use the Drive API via gspread to import a CSV file. Here's an example:

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)

相关问题:使用gspread将CSV文件上传到Google表格

这篇关于如何使用Google Sheets API V4导入CSV文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆