我正在为本地化测试编写google工作表验证脚本。我已经陷入了一些逻辑。该脚本的目的是1)遍历所有选项卡。 2)在第2行找到具有文本"通过/失败"的列。最后,3)迭代该列并返回表示失败的行。
要查看的正确脚本称为combined()。我认为第1步接近正确。步骤2目前已被硬编码,并且不是动态搜索行的文本。第3步已经完成。
任何帮助都会很棒:)!提前谢谢。
https://docs.google.com/spreadsheets/d/1mJfDtAi0hHqhqNB2367OPyNFgSPa_tW9l1akByaTSEk/edit?usp=sharing
/*This function is to cycle through all spreadsheets.
On each spreadsheet, it will search the second row for the column that says "Pass/Fail".
Lastly, it will take that column and look for all the fails and return that row*/
function combined() {
var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();
var r =[];
for (var i=0 ; i<sheets.length ; i++){//iterate through all the sheets
var sh = SpreadsheetApp.getActiveSheet();
var data = sh.getDataRange().getValues(); // read all data in the sheet
//r.push("test1"); //Testing to make sure all sheets get cycled through
/*I need something here to find which column on row two says "Pass/Fail"*/
for(i=3;i<data.length;++i){ // iterate row by row and examine data in column A
//r.push("test2"); //Testing to make sure the all
if(data[i][7]=='Fail'){ r.push(data[i])}; // if column 7 contains 'fail' then add it to the list
}
}
return r; //Return row of failed results on all tabs
}
答案 0 :(得分:0)
首先,它会在g
列检索数据。它从数据中检索结果。结果是二维数组。 2D阵列的每个元素的索引表示纸张索引。如果工作表不包含列g
中的值,则元素长度为0.
例如,在以下情况下,
g
中的值。g
中的值。有&#34;失败&#34;行号为3,4,5的值。g
中的值。有&#34;失败&#34;行号为6,7,8的值。结果(return r
)变为低于。
[[], [3, 4, 5], [6, 7, 8]]
示例脚本1:
function combined() {
var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();
var data =[];
sheets.forEach(function(ss){
try { // In the case of check all sheets, if new sheet is included in the spreadsheet, an error occurs. This ``try...catch`` is used to avoid the error.
data.push(ss.getRange(3, 7, ss.getLastRow(), 1).getValues());
} catch(e) {
data.push([]);
}
});
var r = [];
data.forEach(function(e1, i1){
var temp = [];
e1.forEach(function(e2, i2){
if (e2[0] == "Fail") temp.push(i2 + 3);
});
r.push(temp);
});
return r;
}
如果我误解了你的问题,我很抱歉。