Вопрос

How can I determine the path of the currently open document in an OpenOffice or LibreOffice document? I want to forward the path to an external application.

More specifically I want to launch an external player from impress with a video file in full-screen mode:

Shell("/usr/bin/mplayer", 2, """ -fs"" some-file-in-same-dir-as-document.mp4")

For the last parameter I would need the path to the currently opened document in order to append it. Not specifying the path results in referring to the current path (as given by the CurDir() function) which is something different.

Is there actually a good reference for LibreOffice Macros? The only relatively good (but hard to search) document I have found is "OpenOffice Macros Explained" by Andrew Pitonyak.

Это было полезно?

Решение

In the meantime I have found a feasible solution. Look here:

Sub RunSomeMovie
    GlobalScope.BasicLibraries.loadLibrary("Tools")
    Shell("/usr/bin/mplayer -fs ", 2, "" & Tools.Strings.DirectoryNameoutofPath(ThisComponent.getURL(),"/") & "/media/somemovie.mp4")
End Sub

Другие советы

to get the current document path you use this simple command:

ThisComponent.getURL()

CurDir() is simply not reliable for all OS BTW I found that info in the Pitonyak book you cited that I didn't knew and found very precious so thanks for sharing it.

I'm working with LibreOffice 4.2.0.4 and the following Code works for me:

    Dim Dir as String
    GlobalScope.BasicLibraries.loadLibrary("Tools")
    Dir = Tools.Strings.DirectoryNameoutofPath(ThisComponent.url, "/")

The variable "dir" contains now the path of the current document.

Document has a location only if it is saved (or opened from a saved). In addition a Form opened from within LibreOffice Base does not have by its own a location. Only the odt has a location. Hence although:

ThisComponent.hasLocation()

returns True, the location is an empty string (consider it as a bug). To obtain the location, in such cases, you have to access the "Parent":

ThisComponent.Parent.hasLocation() (or ThisComponent.Parent.getURL())

Of course you then have to "traslate" it to readable with: Tools.Strings.DirectoryNameoutofPath

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top