Inserting a python list in a column in google sheet using gspread and sheet api

Question:

I have a python list which contains a list of software names:
list = [‘CodeBlocks’, ‘Foxit Software’, ‘GSettings’, ‘Wintertree’, ‘WordWeb’]

I want to insert this list in a column in google sheet
enter image description here

how to insert it using gspread and api in python

Asked By: ijahan

||

Answers:

From I have a python list which contains a list of software names: list = ['CodeBlocks', 'Foxit Software', 'GSettings', 'Wintertree', 'WordWeb'], I want to insert this list in a column in google sheet enter image description here and how to insert it using gspread and api in python, I believe your goal is as follows.

  • You want to put the value of list = ['CodeBlocks', 'Foxit Software', 'GSettings', 'Wintertree', 'WordWeb'] to the column "E" of Google Spreadsheet using gspread for python.

In this case, how about the following sample script?

Sample script:

import gspread

client = gspread.oauth(###) # Please use your client.

sampleValue = ["CodeBlocks", "Foxit Software", "GSettings", "Wintertree", "WordWeb"] # This is from your question.

spreadsheetId = "###" # Please set your Spreadsheet ID.
sheetName = "Sheet1" # Please set the sheet name.

sheet = client.open_by_key(spreadsheetId).worksheet(sheetName)
sheet.update("E1", [[e] for e in sampleValue], value_input_option="USER_ENTERED")
  • In this sample, ["CodeBlocks", "Foxit Software", "GSettings", "Wintertree", "WordWeb"] is required to convert to [["CodeBlocks"], ["Foxit Software"], ["GSettings"], ["Wintertree"], ["WordWeb"]] at [[e] for e in sampleValue].
  • When this script is run, the values of ['CodeBlocks', 'Foxit Software', 'GSettings', 'Wintertree', 'WordWeb'] is put into the column "E".
  • If you want to set the row number, please modify E1. When E1 is modified to E10, the value is put from "E10".

Note:

  • This sample script supposes that you have already been able to use Sheets API and your client can be used for putting values to Spreadsheet. Please be careful about this. If you want the information about Authorization, you can read it at here.

Reference:

Answered By: Tanaike