我可以使用外部程序在 google 工作表中 运行 自定义脚本吗?

Can i use an external program to run custom scripts in google sheets?

TLDR; .py 脚本可以 运行 一个 Google Apps 脚本吗?

嗨!

通过使用 Google API,我设法创建了一个可以访问和编辑 google sheet 的 .py 脚本。然后我希望程序能够 select sheet 中的自定义 UI 选项卡和 运行 函数(写在内置的 Google Apps 脚本中) .

如果有更简单的方法,我们将不胜感激! :)

我写的程序在这里:

import gspread
from oauth2client.service_account import ServiceAccountCredentials
from pprint import pprint
import datetime

scope = ["https://spreadsheets.google.com/feeds",'https://www.googleapis.com/auth/spreadsheets',"https://www.googleapis.com/auth/drive.file","https://www.googleapis.com/auth/drive"]

creds = ServiceAccountCredentials.from_json_keyfile_name("creds.json", scope)

client = gspread.authorize(creds)

#^this authorizes the programs mail and stuff

sheet = client.open("Proggetest").sheet1 #opens sheet

now = datetime.datetime.now()
ctime = now.strftime("%d.%m.%Y %H:%M:%S") #time and date

sheet.update_cell(5, 5, "updated by prog. : " + ctime) 
#updates cell 5E


#INSERT CODE THAT RUNS APPS SCRIPT HERE:) 

sheet 中的 UI 部分在这里(在内置的 Google Apps 脚本中编写)

var ui = SpreadsheetApp.getUi();

function buildTESTmenu() {

  ui.createMenu('Tests')
    .addSubMenu(ui.createMenu('colours')
      .addItem('Change a cells colour', 'TESTmenu.changeColour')) #.changeColour pulls a function that changes the cells colour
    .addSubMenu(ui.createMenu('Data')
      .addItem('Change number in cell', 'TESTmenu.setValue'))#.setValuepulls a function that changes the cells value to a set number
    .addToUi()
}

非常感谢任何帮助!

谢谢!

你可以运行 through from . But there are limitations。最重要的是,服务帐户不能与 api 一起使用。接下来,当在执行 api 上下文中调用函数时,我认为您无法操纵 ui