How to check if the value exist in google spreadsheet or not using apps script

前端 未结 2 986
粉色の甜心
粉色の甜心 2021-01-17 05:01

How to check if the value is exist in google spreadsheet or not using apps script I want to check if the Sam exist in the entire spreadsheet or not using apps s

2条回答
  •  被撕碎了的回忆
    2021-01-17 05:52

    Depending on if you want to select the range or just always use the whole A:A column. In the former case, do this:

    // this gets the range
    var range = SpreadsheetApp.getActiveRange().getValues();
    
    // this is what you are searching for
    var searchString = "Sam";
    
    // this is whether what you are searching for exists 
    var isSearchStringInRange = range.some( function(row){
        return row[0] === searchString
    });
    
    // then you can proceed to do something like
    if( isSearchStringInRange ){
      // do something
    }
    

提交回复
热议问题