CreateUnoService-funksjon

Innhold
Innholdsliste 🔎︎

# CreateUnoService Function

Instantierer en Uno-tjeneste med ProcessServiceManager.

### Syntaks:

oService = CreateUnoService( UNO service name )

For a list of available services, visit the com::sun::star Module reference page.

### Eksempel:

Eksemplet nedenfor oppretter funksjonen FileExists som bruker tjenesten com.sun.star.ucb.SimpleFileAccess for å teste om en gitt sti er en eksisterende fil.

        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

UNO services have an extensive online documentation in the api.libreoffice.org website. Visit the SimpleFileAccess Service reference page to learn more about the methods provided by the service used in the example above.

### Eksempel:

Følgende kode bruker tjenesten com.sun.star.ui.dialogs.FilePicker for å vise en filåpningsdialog:

    Sub Main
        fName = FileOpenDialog ("Velg en fil")
        Skriv ut "fil valgt: "+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

Lignende emner

Using Calc Functions in Macros