在LibreOffice基本宏中调用内置IRR函数

我试图从LibreOffice基本宏调用IRR函数,但得到一个

非法论据例外

Function Bla() 
  Dim oFunc as Object
  oFunc = createunoservice("com.sun.star.sheet.FunctionAccess")

  Dim args(1) as Variant
  args(0) = Array(3300, -1000, -2000)
  args(1) = 0.1

  Dim vResult as Variant    
  vResult = oFunc.callFunction("IRR", args)
  Print vResult
End Function

调用该函数的正确方法是什么?

回答(1)

2 years ago

显然,这些函数需要一个二维数组 .

Sub CallIRR() 
  Dim oFunc As Object
  oFunc = createUnoService("com.sun.star.sheet.FunctionAccess")

  Dim args(1) As Variant
  args(0) = Array(Array(3300, -1000, -2000))
  args(1) = 0.1

  Dim vResult As Variant    
  vResult = oFunc.callFunction("IRR", args)
  Print vResult
End Sub

为了解决这个问题,我在https://wiki.openoffice.org/wiki/Documentation/DevGuide/Spreadsheets/Function_Handling#Calculating_Function_Results处理了Java示例 .

EDIT

一个类似的问题是How to use LibreOffice functions into Basic?