[Solved] Get useful meta-information about Office & document

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
_savage
Posts: 187
Joined: Sun Apr 21, 2013 12:55 am

[Solved] Get useful meta-information about Office & document

Post by _savage »

Hi,

I’m looking to find useful debug information using UNO about the Office instance and the (Writer) document currently open in it. I found some document metadata in the DocumentProperties of the XDocument interface (e.g. Author, Generator, …).

What I’d also like though, are:
  • Name and version of the currently running Office instance; and
  • More detailed information about the file that’s been loaded, i.e. file format, its version (if available), etc.
Is such information available, and if so, how?

Thanks :super:
Last edited by _savage on Sun Dec 17, 2017 4:27 pm, edited 2 times in total.
Mac 10.14 using LO 7.2.0.2, Gentoo Linux using LO 7.2.3.2 headless.
User avatar
Zizi64
Volunteer
Posts: 11352
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Get useful meta-information about Office & current docum

Post by Zizi64 »

What I’d also like though, are:

Name and version of the currently running Office instance;
GetVersion.ods
(9.22 KiB) Downloaded 446 times
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
_savage
Posts: 187
Joined: Sun Apr 21, 2013 12:55 am

Re: Get useful meta-information about Office & current docum

Post by _savage »

Zizi64 wrote:
GetVersion.ods
Thank you Zizi! I also found a somewhat related question in this forum here. For those interested, here is the Python code based on Zizi’s macro and other resources:

Code: Select all

>>> import uno
>>> sm = uno.getComponentContext().ServiceManager
>>> service = sm.createInstanceWithContext("com.sun.star.configuration.ConfigurationProvider", uno.getComponentContext())
>>> from com.sun.star.beans import PropertyValue                                                        
>>> pv = PropertyValue()
>>> pv.Name = "nodepath"
>>> pv.Value = "/org.openoffice.Setup/Product"
>>> settings = service.createInstanceWithArguments("com.sun.star.configuration.ConfigurationAccess", (pv,))
>>> # Use settings.getProperties() to inspect what properties are available.
>>> settings.getByName("ooName")
'LibreOffice'
>>> settings.getByName("ooSetupVersionAboutBox")
'5.4.3.2'
>>> settings.getByName("ooXMLFileFormatVersion")
'1.0'
More information under Reading Configuration Data, although I couldn’t find anything yet that leads me to configuration/meta data about the currently open document.
Mac 10.14 using LO 7.2.0.2, Gentoo Linux using LO 7.2.3.2 headless.
UnklDonald418
Volunteer
Posts: 1544
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Get useful meta-information about Office & current docum

Post by UnklDonald418 »

I couldn’t find anything yet that leads me to configuration/meta data about the currently open document
Look at sections 13.3 and 13.4 in Andrew Pintonyak's "OpenOffice.org Macros Explained" you may find what you need there.
http://www.pitonyak.org/oo.php
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
_savage
Posts: 187
Joined: Sun Apr 21, 2013 12:55 am

Re: Get useful meta-information about Office & current docum

Post by _savage »

UnklDonald418 wrote:Look at sections 13.3 and 13.4 in Andrew Pintonyak's "OpenOffice.org Macros Explained" you may find what you need there.
http://www.pitonyak.org/oo.php
Thank you! That’s a helpful document you linked there, and using the references I was able to dig up some information about a currently opened Writer document:

Code: Select all

>>> # document = desktop.loadComponentFromURL("file://…", "_blank", 0, None)
>>> props = document.getDocumentProperties()
>>> props.Generator
'Microsoft Macintosh Word'
# 'LibreOffice/5.3.6.1$MacOSX_X86_64 LibreOffice_project/686f202eff87ef707079aeb7f485847613344eb7'
>>> props.DocumentStatistics
(…) # n-tuple of com.sun.star.beans.NamedValues (i.e. name/value pairs).
However, is there no way to find more information about the file type itself, perhaps a file format version? When Writer selects an import filter, then that information must surely be available at some point…
Last edited by _savage on Sun Dec 17, 2017 4:25 pm, edited 1 time in total.
Mac 10.14 using LO 7.2.0.2, Gentoo Linux using LO 7.2.3.2 headless.
User avatar
Zizi64
Volunteer
Posts: 11352
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Get useful meta-information about Office & current docum

Post by Zizi64 »

However, is there no way to find more information about the file type itself, perhaps a file format version? When Writer selects an import filter, then that information must certainly be available at some point…

I suppose it: When the document is loaded by the AOO/LO Writer application into the system memory, then the document format is ODF 1.1 or ODF 1.2. (Depended on the settings in the Tools - Options - Load/Save - General - Default File Formats and ODF settings...)
The AOO/LO Writer (the import filter of the Writer) always converts the opened document into ODF format, because it can work in the native format only. (Of course you can choose another format at the "Save as" function.)

Note: use the XrayTool or the MRI to examine the properties and methods of the objects.)
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
Posts: 11352
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Get useful meta-information about Office & current docum

Post by Zizi64 »

I have found theese properties by the usage of the Xray Tool:
getArgs.png
and I can read some of them by the macrocode of this topic:
viewtopic.php?f=20&t=83822#p389726

see Villeroy's sample codes.

Here is the modified code, that i used to display the name of the FILTER, and other properties:

Code: Select all

REM  *****  BASIC  *****

Option explicit

Sub Main
 Dim oDoc as object
 Dim oProp as object
 Dim args()
 Dim sFullMessage as string
  
 	oDoc = ThisComponent
' 	xray oDoc 
'see the "getArgs" method


	sFullMessage = ""
	args() = oDoc.getArgs

	sFullMessage = sFullMessage & (args(0).Name) & " : " & (args(0).value) & Chr(13)
	sFullMessage = sFullMessage & (args(1).Name) & " : " & (args(1).value) & Chr(13)
'2: error
'3: error
	sFullMessage = sFullMessage & (args(4).Name) & " : " & (args(4).value) & Chr(13)
	sFullMessage = sFullMessage & (args(5).Name) & " : " & (args(5).value) & Chr(13)
	sFullMessage = sFullMessage & (args(6).Name) & " : " & (args(6).value) & Chr(13)
	sFullMessage = sFullMessage & (args(7).Name) & " : " & (args(7).value) & Chr(13)
'8: error
	sFullMessage = sFullMessage & (args(9).Name) & " : " & (args(9).value) & Chr(13)
'10: error
    sFullMessage = sFullMessage & (args(11).Name) & " : " & (args(11).value) & Chr(13)
    
	MsgBox(sFullMessage)
 
End Sub
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
_savage
Posts: 187
Joined: Sun Apr 21, 2013 12:55 am

Re: Get useful meta-information about Office & current docum

Post by _savage »

Great, looks like the “FilterName” property value (one of the values returned by getArgs()) is what I was still looking for :super:

Note, however, that the document statistics for a Writer document may be incomplete if the document hasn’t finished loading. Related threads here or here and probably there are some more.
Mac 10.14 using LO 7.2.0.2, Gentoo Linux using LO 7.2.3.2 headless.
Post Reply