Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 动态验证多个Google工作表选项卡_Javascript_Google Sheets - Fatal编程技术网

Javascript 动态验证多个Google工作表选项卡

Javascript 动态验证多个Google工作表选项卡,javascript,google-sheets,Javascript,Google Sheets,我正在为本地化测试的谷歌表单验证编写脚本。我被一些逻辑所束缚。脚本的目的是1)遍历所有选项卡。2) 查找第2行中文本为“通过/失败”的列。最后,3)遍历该列并返回表示失败的行 要查看的正确脚本称为combined()。我认为第一步几乎是正确的。步骤2目前是硬编码的,不是动态搜索行中的文本。步骤3已经完成 任何帮助都会很好:)!!!提前谢谢 /*此函数用于循环浏览所有电子表格。 在每个电子表格上,它将在第二行搜索显示“通过/失败”的列。 最后,它将获取该列并查找所有的失败并返回该行*/ 函数组合

我正在为本地化测试的谷歌表单验证编写脚本。我被一些逻辑所束缚。脚本的目的是1)遍历所有选项卡。2) 查找第2行中文本为“通过/失败”的列。最后,3)遍历该列并返回表示失败的行

要查看的正确脚本称为combined()。我认为第一步几乎是正确的。步骤2目前是硬编码的,不是动态搜索行中的文本。步骤3已经完成

任何帮助都会很好:)!!!提前谢谢

/*此函数用于循环浏览所有电子表格。
在每个电子表格上,它将在第二行搜索显示“通过/失败”的列。
最后,它将获取该列并查找所有的失败并返回该行*/
函数组合(){
var sheets=SpreadsheetApp.getActiveSpreadsheet().getSheets();
var r=[];

对于(var i=0;i首先,它在
g
列检索数据。它从数据中检索结果。结果是二维数组。二维数组中每个元素的索引表示工作表索引。如果工作表不包括
g
列中的值,则元素长度为0

例如,在以下情况下

  • 表0未在列
    g
    中包含值
  • 表1包括列
    g
    中的值。行号3、4、5处有“失败”值
  • 第2页包括列
    g
    中的值。行号6、7、8处有“Fail”值
结果(
返回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;
}
如果我误解了你的问题,我很抱歉

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;
}