TLDR;.py脚本可以运行Google Apps脚本吗?
嗨!
通过使用Google API,我设法创建了一个.py脚本,该脚本可以访问和编辑Google表格。然后,我希望程序能够在工作表中选择一个自定义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:)
工作表中的用户界面片段位于此处(用内置的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()
}
任何帮助都非常感谢!
谢谢!
您可以从python通过google-apps-script-api运行google-apps-script。但是有局限性。最重要的是,服务帐户不能与api一起使用。接下来,当在执行api上下文中调用函数时,我认为您无法操纵。ui
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句