gpt4 book ai didi

javascript - Google Sheets 脚本查找具有值的单元格

转载 作者:行者123 更新时间:2023-11-28 04:21:37 25 4
gpt4 key购买 nike

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

示例:如果我要搜索的单词在单元格 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 = ???
}
}

}

谢谢。

最佳答案

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

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

关于javascript - Google Sheets 脚本查找具有值的单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45383648/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com