Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/375.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
Javascript 有没有办法检查单元格中的单词?_Javascript_If Statement_Google Apps Script_Google Sheets - Fatal编程技术网

Javascript 有没有办法检查单元格中的单词?

Javascript 有没有办法检查单元格中的单词?,javascript,if-statement,google-apps-script,google-sheets,Javascript,If Statement,Google Apps Script,Google Sheets,我正在寻找一种方法来检查谷歌应用程序脚本和谷歌表单中的单元格是否包含文本 var cell = "Joe, Bob, Tim, John" //I would want this to execute if(cell contains "Tim") { //code } 最近,SpreadsheetApp服务中添加了一个TextFinder类,允许您在实时范围、工作表甚至电子表格本身上执行此操作。有关更多详细信息,请参阅。只需使用createTextFinder在上下文中设置查找器,并将要查

我正在寻找一种方法来检查谷歌应用程序脚本和谷歌表单中的单元格是否包含文本

var cell = "Joe, Bob, Tim, John"

//I would want this to execute
if(cell contains "Tim") {
//code
}
最近,SpreadsheetApp服务中添加了一个TextFinder类,允许您在实时范围、工作表甚至电子表格本身上执行此操作。有关更多详细信息,请参阅。只需使用createTextFinder在上下文中设置查找器,并将要查找的文本作为参数。 对结果TextFinder实例调用findNext方法将返回调用它的范围,如果未找到任何内容,则返回null。例如:

function findText() {

  var sh = getSheet(); //custom function that returns target Sheet;
  var rng = sh.getRange(1,1); //change to desired Range boundaries;

  //create TextFinder and configure;
  var tf = rng.createTextFinder('textToFind');
      tf.matchCase(false); //{Boolean} -> match target text's case or not;
      tf.matchEntireCell(false); //{Boolean} -> check the whole Range or within;
      tf.ignoreDiacritics(true); //{Boolean} -> ignore diacretic signs during match;
      tf.matchFormulaText(false); //{Boolean} -> search in formulas (if any) or values;

  //invoke search;
  var res = tf.findNext();

  //do something with result;
  if(res!==null) {
    var vals = res.getValues();
    Logger.log(vals);
  }

}
最近,SpreadsheetApp服务中添加了一个TextFinder类,允许您在实时范围、工作表甚至电子表格本身上执行此操作。有关更多详细信息,请参阅。只需使用createTextFinder在上下文中设置查找器,并将要查找的文本作为参数。 对结果TextFinder实例调用findNext方法将返回调用它的范围,如果未找到任何内容,则返回null。例如:

function findText() {

  var sh = getSheet(); //custom function that returns target Sheet;
  var rng = sh.getRange(1,1); //change to desired Range boundaries;

  //create TextFinder and configure;
  var tf = rng.createTextFinder('textToFind');
      tf.matchCase(false); //{Boolean} -> match target text's case or not;
      tf.matchEntireCell(false); //{Boolean} -> check the whole Range or within;
      tf.ignoreDiacritics(true); //{Boolean} -> ignore diacretic signs during match;
      tf.matchFormulaText(false); //{Boolean} -> search in formulas (if any) or values;

  //invoke search;
  var res = tf.findNext();

  //do something with result;
  if(res!==null) {
    var vals = res.getValues();
    Logger.log(vals);
  }

}

您可以使用split使其成为数组,然后使用includes方法。@Xp.L Google Apps脚本不包含内置的对includes的支持,因此需要polyfill。您可以使用split使其成为数组,然后使用includes方法。@Xp.L Google Apps脚本不包含内置的对includes的支持,因此需要polyfill。