具有任意数量参数的 LibreOffice Calc 自定义函数
LibreOffice Calc Custom Function with arbitrary number of arguments
我正在尝试在 LibreOffice Calc 中编写一个具有任意数量参数的自定义函数。如果可能的话,有人知道吗?一个例子:
Function sum_custom(a,b,c)
sum_custom = a+b+c;
End Function
是否可以扩展此函数,使其可以接受任意数量的参数?
PS:不是关于实际总和,而是关于参数个数..
使用 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)
我正在尝试在 LibreOffice Calc 中编写一个具有任意数量参数的自定义函数。如果可能的话,有人知道吗?一个例子:
Function sum_custom(a,b,c)
sum_custom = a+b+c;
End Function
是否可以扩展此函数,使其可以接受任意数量的参数?
PS:不是关于实际总和,而是关于参数个数..
使用 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)