Run python code from google spreadsheets?

In excel, you can create custom functions using python with pyxll. I am moving to Google spreadsheets and using their Google script application, but the libraries are much larger and better in python, I would like a way to create custom functions using python from Google spreadsheets. There are ways python interacts with Google sheets, such as gspread. Is there a way to run python in a Google application and then get a worksheet to run this code? What other ways to run Python code from Google spreadsheets?

+4
source share
2 answers

One way is to have some code that reads the spreadsheet all the time, and then runs another code when the condition is met.

Without GAE, you can use the following code:

#http://code.google.com/p/gdata-python-client/downloads/list
import gdata.spreadsheet.service as s

spreadsheet_key = 'spreadsheetkey'# https://docs.google.com/spreadsheet/ccc?key=<spreadsheet key>&usp=sharing#gid=0

worksheet_key = 'od6' #first tab
gd_client = s.SpreadsheetsService(spreadsheet_key, worksheet_key)
gd_client.email = 'user@gmail.com'
gd_client.password = 'password'
gd_client.ProgrammaticLogin()
list_feed = gd_client.GetListFeed(spreadsheet_key, worksheet_key)
for entry in list_feed.entry:
    #read cell values and then do something if the condition is met

If you want the spreadsheet launch code to be used in the GAE application, you can publish the spreadsheet and create the spreadsheet URL (JSON) as follows: https://spreadsheets.google.com/feeds/list/(spreadsheetkey)/ od6 / public / values? alt = json This address can be obtained through the application, cell values ​​can be read, and some code can be run.

: - , - . , ( GAE, ), Google.

+1

- GAE, Google Apps Script UrlFetch. , Script.

Script

function myFunction(){
  //your code
  //Call the webservice
 var response = UrlFetchApp.fetch('my_webservice_url', {payload:'...', method:'POST'});
 Logger.log(response.getContentText());
 // your code based on response
}

, , Script

+2

Source: https://habr.com/ru/post/1535463/


All Articles