【问题标题】:How can I combine these two formulas?如何结合这两个公式?
【发布时间】:2020-02-21 12:30:46
【问题描述】:

Example

我想把这两个公式结合起来,但是'和'好像不行吗?

我想输出一个表,其中包含源表中的数据,其工作表名称已在工作表FL-elever 中签入:

  • 加入公式:

  • 要过滤的已检查名称:

  • 源表格式:

【问题讨论】:

  • 你在说什么公式?
  • 查看所需的输出表
  • 你能解释一下想要的输出是什么吗?
  • 第一个公式检查检查名称表中的名称。第二个公式显示来自三个 Prename 表的合并视图。我想要做的是使第二个公式动态化,因此只包含选中的名称。

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


【解决方案1】:

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

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

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

定义后,您可以像使用任何工作表内置函数一样使用此函数:

参考:

【讨论】:

  • 好的 - 我已经尝试过你的脚本解决方案,即使它有效,但对我和这个项目来说太复杂了。我会尊重你的回答,但我离我想要的输出还很远。我将添加一个新的 - 已更改的 - 问题。
猜你喜欢
  • 2017-06-10
  • 1970-01-01
  • 1970-01-01
  • 2021-04-08
  • 1970-01-01
  • 2017-07-03
  • 1970-01-01
相关资源
最近更新 更多