Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script 从if语句调用Google脚本函数_Google Apps Script_Google Sheets - Fatal编程技术网

Google apps script 从if语句调用Google脚本函数

Google apps script 从if语句调用Google脚本函数,google-apps-script,google-sheets,Google Apps Script,Google Sheets,我正在使用Google脚本,我只想运行一个基于单元格内容的函数。我知道这看起来像一个公式,但我想它作为一个脚本 =if(T2="*",SplitNames,fullNames); 因此,如果T2包含任何文本,则运行函数SplitNames。否则运行函数全名 请问这个怎么写?谢谢。您只需要一个简单的if语句,该语句基于单元格“T2”的值,我在下面将其定义为var cell: function checkT2() { var sh = SpreadsheetApp.getActiveSprea

我正在使用Google脚本,我只想运行一个基于单元格内容的函数。我知道这看起来像一个公式,但我想它作为一个脚本

=if(T2="*",SplitNames,fullNames);
因此,如果T2包含任何文本,则运行函数
SplitNames
。否则运行函数
全名


请问这个怎么写?谢谢。

您只需要一个简单的
if
语句,该语句基于单元格“T2”的值,我在下面将其定义为
var cell

function checkT2() {
  var sh = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  var cell = sh.getRange("T2").getValue();

  //check if cell is not empty
  if (cell) {
    SplitNames();
  } else {
    fullNames();
  }
}

参考资料:

您需要的是获取手机内容,然后进行测试:

yourFunction()
{
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var T2 = ss.getRangeByName("T2").getValue()//get the content of the cell T2 in the variable T2
  if(T2=="*")
    splitnames();//assuming you have a function splitnames in your script file
  else
    fullnames();

}

你是想把它写成谷歌表单公式还是在你的谷歌应用脚本中?在谷歌应用脚本中。我知道如何表达我的意思的唯一方法就是让它看起来像一个公式!!哈哈,我错过了什么。显然是新来的论坛,所以仍然在寻找我的方式。感谢您的帮助。@TheMaster如果用户试图通过公式执行此操作,那就太好了-直到后来我才意识到他们可能试图以公式为例来描述逻辑。@ross我明白了………谢谢@LALLEMENT.E此脚本确实在做些什么。如果T2的内容是文本,会有区别吗?我在想“*”是指任何文本。似乎它只想运行SplitNames函数,而不管引号之间是什么。Thanks我认为测试T2==“*”只有当单元格T2中的值是字符*时才是真的。如果您想测试T2的内容类型,您应该改为:If(T2 instanceof String)。现在,如果我正确理解了要执行的操作,那么应该在函数splitnames()和fullnames()的参数中传递变量T2。所以你应该这样写:splitnames(T2);另外,你能告诉我你的函数splitnames和fullnames的代码是什么吗。我想测试T2中al的任何文本,然后根据结果运行一个函数或另一个函数。谢谢你,我要去看戏!好的,但是函数splitnames()和fullnames()是否与脚本位于同一文件中?T2不是单元格的内容,如果要访问内容,需要使用方法T2.getValue(),如果要检查T2是否为空,可以通过if(T2.getValue==“”)执行