【问题标题】:Google Sheets Script Find Cell with ValueGoogle表格脚本查找具有值的单元格
【发布时间】:2017-07-28 23:17:37
【问题描述】:

如何在列中搜索单词,然后获取包含该单词的单元格的位置?

示例:如果我要搜索的单词在单元格 A6 中找到,我想获取 A6。

我下面的代码能够找到“xyz”这个词,但我不知道如何在变量中记录它的单元格位置。

function search() {

  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();

  for(var i=1;i<sheet.getLastRow();i++){
    var value = sheet.getRange(i, 1).getValue();

    if(value == 'xyz'){
          //how do I get the cell location of xyz?
          var cell = ???
    }
  }

}

谢谢。

【问题讨论】:

标签: javascript google-apps-script google-sheets


【解决方案1】:

当条件语句为真时,单元格的位置将是i 的值和列值。

if(value == 'xyz'){
  //i is the row
  //1 is the column
  var cell = sheet.getCell(i,1);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-01-17
    • 1970-01-01
    • 1970-01-01
    • 2014-09-04
    • 1970-01-01
    • 1970-01-01
    • 2021-10-20
    相关资源
    最近更新 更多