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

问题描述

TLDR; .py 脚本能否运行 Google Apps 脚本?

嗨!

通过使用 Google Api,我设法创建了一个可以访问和编辑 Google 表格的 .py 脚本。然后,我希望该程序能够在工作表中选择一个自定义 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:) 

工作表中的 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()
}

非常感谢任何帮助!

谢谢!

解决方法

您可以从 运行 。但是有limitations。最重要的是,服务帐户不能与 api 一起使用。接下来,当在执行 api 上下文中调用函数时,我认为您无法操作 ui

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...