Funkce CreateUnoService

Vytvoří instanci služby Uno se službou ProcessServiceManager.

Syntaxe:

CreateUnoService(serviceName As String) As Object
tip

Seznam dostupných služeb naleznete na stránce s popisem modulu com::sun::star.


Příklad:

Následující příklad vytvoří funkci FileExists využívající službu com.sun.star.ucb.SimpleFileAccess k otestování toho, zda zadaná cesta odpovídá existujícímu souboru.

Function FileExists(sPath as String) As Boolean
    Dim svcSFA As Object
    Set svcSFA = CreateUnoService("com.sun.star.ucb.SimpleFileAccess")
    Dim bExists As Boolean : bExists = svcSFA.exists(sPath)
    Dim bIsFolder As Boolean : bIsFolder = svcSFA.IsFolder(sPath)
    FileExists = bExists And Not bIsFolder
End Function ' FileExists
tip

Služby UNO mají obsáhlou dokumentaci online na stránce api.libreoffice.org. Další informace o metodách služby použité v předchozím příkladu naleznete na stránce služby SimpleFileService.


Příklad:

Následující kód používá pro zobrazení dialogového okna pro výběr souboru službu com.sun.star.ui.dialogs.FilePicker.

Sub Main
    fName = FileOpenDialog ("Vyberte, prosím, soubor")
    Print "vybraný soubor: "+fName
End Sub

Function FileOpenDialog(title As String) As String
    res = com.sun.star.ui.dialogs.ExecutableDialogResults
    filepicker = CreateUnoService("com.sun.star.ui.dialogs.FilePicker")
    filepicker.Title = title
    If res.OK = filepicker.execute() Then
        files = filepicker.getSelectedFiles()
        FileOpenDialog=files(0)
    EndIf
End Function ' Main

Podpořte nás!