如何结合这两个公式?

时间:2020-02-21 12:30:46

标签: multidimensional-array google-sheets google-sheets-formula textjoin

http://localhost:/8888/api/quiz

我想将这两个公式结合起来,但是'和'似乎不正确?

我要输出一个包含源表中数据的表,该源表的工作表名称已在工作表FL-elever中检查:

  • 要加入的公式:

Example

  • 已检查名称以进行过滤:

enter image description here

  • 源表格式:

enter image description here

1 个答案:

答案 0 :(得分:0)

您可以使用Apps脚本Custom Function来做到这一点。

首先,通过选择Tools > Script editor打开绑定脚本,然后将以下函数复制到脚本中(检查内联注释):

function POPULATE_TABLE() {
  var output = new Array(6).fill("").map(function() { 
    return new Array(5).fill(""); // Initialize the 2D array you will output
  });
  var ss = SpreadsheetApp.getActive();
  // Get the rows in which checkbox is marked:
  var FLelever = ss.getSheetByName("FL-elever");
  var checkedNames = FLelever.getDataRange().getValues().slice(1).filter(function(row) {
    return row[5] === true;
  });
  checkedNames.forEach(function(checkedName) { // Iterate through each row with marked checkbox
    var sheetName = checkedName[0] + "-" + checkedName[1]; // Get sheet name (column A + "-" + column B)
    var sheet = ss.getSheetByName(sheetName); // Get corresponding sheet
    if (sheet) { // Check that sheet exists
      // Get the source table from the corresponding sheet:
      var firstRow = 2;
      var firstCol = 2;
      var numRows = sheet.getLastRow() - firstRow + 1;
      var numCols = sheet.getLastColumn() - firstRow + 1;
      var values = sheet.getRange(firstRow, firstCol, numRows, numCols).getValues();
      // Iterate through the source table and add the existing values to output:
      for (var i = 0; i < values.length; i++) {
        for (var j = 0; j < values[i].length; j++) {
          if (output[i][j] !== "" && values[i][j] !== "") {
            output[i][j] = output[i][j].concat(", ");
          }
          output[i][j] = output[i][j].concat(values[i][j]); // Concatenate values
        }
      }
    }    
  });
  return output;
}

一旦定义,您就可以像使用任何图纸内置功能一样使用此功能:

enter image description here

参考: