【发布时间】:2020-06-02 17:38:52
【问题描述】:
我有一个谷歌表,其中 B 列的每个单元格中都有一个公式,它根据特定条件使用 IF 公式返回“Y”或“N”。
我想做的是创建一个每小时运行的谷歌脚本(通过可安装的触发器)并在 B 列中搜索单元格中所有带有“Y”的行。然后我希望它获取这些行并从 C 列中提取值,然后使用这些值通过使用 C 中的值为该行推送另一个函数,并在该行的 D 列中返回结果,然后对其中的每一行重复在 B 列中找到“Y”。根据 Stack 中的搜索,我找到了将搜索该列的代码。但我不知道如何使用数据从相邻列 C 中提取值以推动我的其他函数,然后在 D 列中返回结果。此外,在对这段代码运行简单测试时,它看起来像是唯一的运行第 2 行,而不搜索工作表中的任何其他行。
function onSearch()
{
var searchString = "Y";
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Copy of DataFinal");
var column =2; //column Index
var columnValues = sheet.getRange(2, column, sheet.getLastRow()).getValues(); //1st is header row
var searchResult = columnValues.findIndex(searchString); //Row Index - 2
if(searchResult != -1)
{
//searchResult + 2 is row index.
SpreadsheetApp.getActiveSpreadsheet().setActiveRange(sheet.getRange(searchResult + 2, 3)).setValue("found here");
}
这是我想包含在搜索脚本下的代码,然后将找到的行(带有“Y”)中的值推送到 D 列,并将另一个函数(如下所示)的结果返回到 D 列。
var timedis = gettime(value) \\ this is where i would take the value from column C push it through my other function
o.setValue(timedis). \\ the result of gettime (timedis) is what i woudld like to put in column D in the same row and then repeat for all rows where "Y" was found in B.
}
function gettime(f) {
\\my other function script would go here. No help needed on this part.
return timedis
}
【问题讨论】:
标签: google-sheets