Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
【Python】GoogleスプレッドシートAPI
from google import spreadsheet
class WorkSheet(object):
spreadsheetId = ''
def __init__(self, spreadsheetId):
self.spreadsheetId = spreadsheetId
def get(self, range):
result = spreadsheet().spreadsheets().values().get(
spreadsheetId=self.spreadsheetId, range=range
).execute()
return result.get('values', [])
def update(self, range, body):
spreadsheet().spreadsheets().values().update(
spreadsheetId=self.spreadsheetId, range=range,
valueInputOption="USER_ENTERED", body=body
).execute()
if __name__ == '__main__':
worksheet = WorkSheet("spreadsheetId")
# A列からC列までの値を取得
print(worksheet.get_values('A:C'))
# E1とG1に値を挿入
worksheet.update('E1:G1', {'values': [1,2]})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment