Googleのスプレッドシートを読み書きできるプログラムを作りました。 勿論先人がいっぱいいるんですけど、どれも若干IDの取り方など違ったようなので自分なりにやってみました。
import os
import gspread
from oauth2client.service_account import ServiceAccountCredentials
scope = ['https://spreadsheets.google.com/feeds']
path = os.path.expanduser("JSONファイルへのパス")
credentials = ServiceAccountCredentials.from_json_keyfile_name(path, scope)
client = gspread.authorize(credentials)
gfile = client.open_by_url('スプレッドシートの共有用URL')
//テキストファイルの読み込んだ内容をシートに書き込みます
f = open('result.txt')
line = f.readline()
while line:
if line == "\n":
print "Empty"
else:
words = line.split()
worksheet = gfile.worksheet(words[0])
values_list_retsu = worksheet.col_values(1)
values_list_gyo = worksheet.row_values(1)
for h in values_list_gyo:
for i in values_list_retsu:
if i == words[1]:
worksheet.update_acell('I2', words[2])
line = f.readline()
f.close


