Page 1 of 1

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

Posted: Mon Dec 11, 2017 1:45 am
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:

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

Posted: Tue Dec 12, 2017 6:32 pm
by Zizi64
What I’d also like though, are:

Name and version of the currently running Office instance;
GetVersion.ods
(9.22 KiB) Downloaded 595 times

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

Posted: Wed Dec 13, 2017 9:23 am
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.

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

Posted: Sat Dec 16, 2017 10:19 pm
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

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

Posted: Sun Dec 17, 2017 1:39 pm
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…

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

Posted: Sun Dec 17, 2017 2:51 pm
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.)

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

Posted: Sun Dec 17, 2017 3:28 pm
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

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

Posted: Sun Dec 17, 2017 4:19 pm
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.