How do I search Google Spreadsheets?

前端 未结 5 1146
心在旅途
心在旅途 2020-11-30 09:24

I am doing a few exhaustive searches and need to determine if a new domain (URL) is already in a Spreadsheet. However, none of the Spreadsheet objects have search functions,

5条回答
  •  醉梦人生
    2020-11-30 10:09

    Unfortunately there is no searching functionality in the Spreadsheet services. You can get the data for the range you are searching on, and then iterate over it looking for a match. Here's a simple function that does that:

    /**
     * Finds a value within a given range. 
     * @param value The value to find.
     * @param range The range to search in.
     * @return A range pointing to the first cell containing the value, 
     *     or null if not found.
     */
    function find(value, range) {
      var data = range.getValues();
      for (var i = 0; i < data.length; i++) {
        for (var j = 0; j < data[i].length; j++) {
          if (data[i][j] == value) {
            return range.getCell(i + 1, j + 1);
          }
        }
      }
      return null;
    }
    

提交回复
热议问题