CreateUnoService 函数

使用 ProcessServiceManager 实例化 Uno 服务。

语法:

oService = CreateUnoService( Uno 服务名称 )

可用服务的列表请见: https://api.libreoffice.org/docs/idl/ref/namespacecom_1_1sun_1_1star.html

示例:

Calling Calc functions in Basic:


    Function MyVlook(item, InRange As Object, FromCol As Integer)
        Dim oService As Object
        oService = createUnoService("com.sun.star.sheet.FunctionAccess")
        REM Always use the function English name
        MyVlook = oService.callFunction("VLOOKUP",Array(item, InRange, FromCol, True))
    End Function

示例:

oIntrospection = CreateUnoService( "com.sun.star.beans.Introspection" )

以下代码使用了一个可打开文件打开对话框的服务:


Sub Main
    fName = FileOpenDialog ("请选择文件")
    Print "选择的文件: "+fName
End Sub
 
Function FileOpenDialog(title As String) As String
    filepicker = createUnoService("com.sun.star.ui.dialogs.FilePicker")
    filepicker.Title = title
    filepicker.execute()
    files = filepicker.getFiles()
    FileOpenDialog=files(0)
End Function