LibreOffice Calc自定义函数,具有任意数量的参数

时间:2015-03-07 15:42:27

标签: libreoffice-calc

我正在尝试在LibreOffice Calc中编写一个具有任意数量参数的自定义函数。有没有人知道这是否可能?一个例子:

Function sum_custom(a,b,c) sum_custom = a+b+c; End Function

是否可以扩展此功能以便可以使用任意数量的参数?

PS:它与实际总和无关,它与论证的数量有关。

1 个答案:

答案 0 :(得分:1)

使用Excel VBA可以使用ParamArray:https://msdn.microsoft.com/en-us/library/538f81ec.aspx

至少在Libreoffice的最新版本中,如果设置了Option Compatible,也可以使用ParamArray。

示例:

Option Compatible

public function sum_custom(ParamArray arr_args() as Variant) as Double
 sum_custom = 0
 for i = lbound(arr_args) to ubound(arr_args) 
  sum_custom = sum_custom + arr_args(i)
 next
end function

可以用作

=SUM_CUSTOM(1;2;3)

=SUM_CUSTOM(A1;A2;A3;A4)

相关问题