问题描述
即使是最简单的 Google Apps 脚本,我也无法运行,例如,当我通过将电子表格的单元格设置为 =pantsHate(Y)
来运行此脚本时,我收到此错误:
I'm having trouble running even the simplest Google Apps Scripts, for instance when I run this script by setting a cell my spreadsheet to =pantsHate(Y)
I'm getting this error:
错误:您没有权限调用 msgBox
function pantsHate(pref) {
var preference = pref;
switch (preference) {
case "Y":
Browser.msgBox("You hate pants.");
break;
case "N":
Browser.msgBox("You do not hate pants.");
break;
default:
Browser.msgBox("You hate answering Y or N");
break;
}
return pref;
}
我的最终目标是编写一个小函数来操作日期,特别是我需要找出两个日期之间经过了多少天(闰年、特定天数/月等都是因素).这个程序只是一个测试,但我似乎已经做错了什么……非常感谢任何帮助!
My end goal is to write a small function to manipulate dates, specifically I need to find exactly how many days have passed between two dates (leap years, specific days / month, etc are all factors). This program was just a test but I seem to be doing something wrong already... any help is greatly appreciated!
更新:我在一个新项目中尝试了这个并且它有效......arg!
更新 2:用 =pantsHate("Y")
再次运行它,我得到了同样的错误,在这个新"项目中......为什么是谷歌,为什么?
Update: I tried this in a new project and it worked... arg!
Update 2: Ran it again with =pantsHate("Y")
and I got the same error, in this "new" project... why Google, why?
推荐答案
自定义函数只会向它们所在的单元格返回一个值,除非返回一个可能影响连续单元格的数组.
Custom functions will do nothing but return a value to a cell in which they reside unless the return an array which may affect contiguous cells.
自定义函数无法启动消息框(Browser.msgbox())
A custom function cannot initiate a message box(Browser.msgbox())
自定义函数是在电子表格单元格中作为公式的全部或部分输入的函数,它从脚本编辑器调用函数.当您声明:
A custom function is a function entered as all or part of a formula in a spreadsheet cell that calls a function from the script editor. When you state:
例如,当我通过将电子表格的单元格设置为 =pantsHate(Y) 来运行此脚本时,我收到此错误:
=pantsheet(Y) 是一个自定义函数,因为您是从电子表格公式调用它并且它无法启动 Browser.msgbox()
=pantsheet(Y) is a custom function because you are calling it from a spreadsheet formula and it cannot initiate a Browser.msgbox()
这篇关于无权在 Google Apps 脚本中调用 msgBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!