变体数组自定义函数Google表格?以VBA为例

下面的以下函数将在Excel工作表的每一列中添加“ 1”。如果我将= vbe(12)放在A1中,它将在“ A1:L1”列中放入“ 1”。如何将该VBA转换为适用于Google表格的JavaScript?

Function vbe(Num As Long) As Variant
   Dim ary As Variant
   Dim i As Long
   ReDim ary(Num - 1)
   For i = 0 To Num - 1
      ary(i) = 1
   Next i
   vbe = ary
End Function

变体数组自定义函数Google表格?以VBA为例

shuaiqipeng 回答:变体数组自定义函数Google表格?以VBA为例

您可以编写一个自定义公式,以创建长度为指定参数的“ 1”数组,例如

function myFunction(numberColumns) {
  var ones=[];
  ones[0]=[];
  for(var i=0;i<numberColumns;i++){
    ones[0].push(1);
  }
  return ones;
}

现在,您只需要从单元格中调用函数,例如通过键入

=myFunction(12)

有关Custom Functions in Google SheetsGoogle Apps Script的文档中可以找到有用的信息。

本文链接:https://www.f2er.com/2824485.html

大家都在问