I have a list in Python which I simply want to write (append) in the first column row-by-row in a Google Sheet. I'm done with all the initial authentication part, and here's the code:
credentials = GoogleCredentials.get_application_default()
service = build('sheets', 'v4', credentials=credentials)
I do not have any clue as to how I could possibly do this in an easy way.
How about this sample script? This sample appends list
to column A. The list as data is 2 dimensional array. Please be careful for this. In order to use this script, please enable Sheet API v4 at API console.
Sample script :
credentials = GoogleCredentials.get_application_default()
service = build('sheets', 'v4', credentials=credentials)list = [["valuea1"], ["valuea2"], ["valuea3"]]
resource = {"majorDimension": "ROWS","values": list
}
spreadsheetId = "### spreadsheet ID"
range = "Sheet1!A:A";
service.spreadsheets().values().append(spreadsheetId=spreadsheetId,range=range,body=resource,valueInputOption="USER_ENTERED"
).execute()
You can see the detail information of spreadsheets.values.append at here.
If this sample was not useful for you, I'm sorry.