Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.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
Google apps script 将数组传递到包装在ArrayFormula中的自定义函数?_Google Apps Script_Google Sheets_Array Formulas_Custom Function - Fatal编程技术网

Google apps script 将数组传递到包装在ArrayFormula中的自定义函数?

Google apps script 将数组传递到包装在ArrayFormula中的自定义函数?,google-apps-script,google-sheets,array-formulas,custom-function,Google Apps Script,Google Sheets,Array Formulas,Custom Function,我有一个电子表格,其中包含出于格式化原因而使用合并单元格的列。我试图创建镜像第一组列的列,但在所有受影响的行上使用了合并的单元格值。多亏了我在网上找到的一个自定义函数,我才能做到这一点。我不能做的是将其包含在一个数组公式中,我不知道为什么 以下是电子表格的小版本: 自定义功能是: /** * Takes into account merged cells and returns the value of the merged cell * for all the cells within t

我有一个电子表格,其中包含出于格式化原因而使用合并单元格的列。我试图创建镜像第一组列的列,但在所有受影响的行上使用了合并的单元格值。多亏了我在网上找到的一个自定义函数,我才能做到这一点。我不能做的是将其包含在一个数组公式中,我不知道为什么

以下是电子表格的小版本:

自定义功能是:

/**
* Takes into account merged cells and returns the value of the merged cell 
* for all the cells within the merged range, rother than just the top left 
* cell of the merged range.
*
* Copied from https://webapps.stackexchange.com/questions/110277/how-do-i-reference-the-values-of-merged-cells-in-formulas
*
* Used by Patrick Duncan. - 7 May 2018
*/

function cellVal(cellAddress) {
  var cell = SpreadsheetApp.getActiveSheet().getRange(cellAddress);  
  return (cell.isPartOfMerge() ? cell.getMergedRanges()[0].getCell(1, 1) : cell).getValue();
}
无阵列公式的公式为:

=cellVal2(索引(地址(行(),5,4)))

我所尝试的是:

=arrayformula(cellVal2(索引(地址(E3:E行,5,4)))

知道我做错了什么吗

干杯


帕特里克

这次修改怎么样?我认为有几种方法可以解决你的情况。所以,请把这看作是其中之一

修改点:
  • 索引(地址(行(E3:E30),5,4))
    被赋予
    单元地址时,
    单元地址
    [“E3”],[“E4”],[“E5”],,,,,]
    。这是一个二维数组。
    • getRangeList()
      展平此二维数组
  • 使用
    getRangeList()
    将展平数组转换为范围数组
  • 使用转换的范围检索每个值并返回它们
修改脚本: 用法: 当您使用此自定义函数时,请按如下方式使用

=ARRAYFORMULA(cellVal3(index(address(row(E3:E30),5,4))))

参考资料:

如果我误解了您的问题,我很抱歉。

我应该补充一点,我想将此公式包装在一个数组公式中的原因是,如果后续用户在电子表格中插入其他行,则公式仍然适用,而他们不必做任何事。这意味着我可以隐藏镜像列。
=ARRAYFORMULA(cellVal3(index(address(row(E3:E30),5,4))))
=cellVal3(index(address(row(E3:E30),5,4)))