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

时间:2018-01-25 17:41:59

标签: libreoffice basic openoffice-calc libreoffice-calc libreoffice-basic

我试图从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 个答案:

答案 0 :(得分:0)

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

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示例。

修改

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