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

The Application Programming Interface and the OASIS Open Document Format

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

Postby _savage » Mon Dec 11, 2017 1:45 am

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.11 using LO 5.3.6.1, Gentoo Linux using LO 5.3.4.2 headless.
_savage
 
Posts: 164
Joined: Sun Apr 21, 2013 12:55 am

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

Postby Zizi64 » Tue Dec 12, 2017 6:32 pm

What I’d also like though, are:

Name and version of the currently running Office instance;


GetVersion.ods
(9.22 KiB) Downloaded 79 times
Tibor Kovacs, Hungary; LO4.4.7, LO6.1.5 on Win7-10 x64Prof.
PortableApps, winPenPack: LO3.3.0-6.2.2; AOO4.1.5
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: 7814
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

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

Postby _savage » Wed Dec 13, 2017 9:23 am

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   Expand viewCollapse view
>>> 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.11 using LO 5.3.6.1, Gentoo Linux using LO 5.3.4.2 headless.
_savage
 
Posts: 164
Joined: Sun Apr 21, 2013 12:55 am

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

Postby UnklDonald418 » Sat Dec 16, 2017 10:19 pm

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.6 & LibreOffice 6.1.5.2 - Windows 10 Professional
UnklDonald418
Volunteer
 
Posts: 1083
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

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

Postby _savage » Sun Dec 17, 2017 1:39 pm

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   Expand viewCollapse view
>>> # 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.11 using LO 5.3.6.1, Gentoo Linux using LO 5.3.4.2 headless.
_savage
 
Posts: 164
Joined: Sun Apr 21, 2013 12:55 am

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

Postby Zizi64 » Sun Dec 17, 2017 2:51 pm

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; LO4.4.7, LO6.1.5 on Win7-10 x64Prof.
PortableApps, winPenPack: LO3.3.0-6.2.2; AOO4.1.5
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: 7814
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

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

Postby Zizi64 » Sun Dec 17, 2017 3:28 pm

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:
https://forum.openoffice.org/en/forum/v ... 22#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   Expand viewCollapse view
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; LO4.4.7, LO6.1.5 on Win7-10 x64Prof.
PortableApps, winPenPack: LO3.3.0-6.2.2; AOO4.1.5
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: 7814
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

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

Postby _savage » Sun Dec 17, 2017 4:19 pm

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.11 using LO 5.3.6.1, Gentoo Linux using LO 5.3.4.2 headless.
_savage
 
Posts: 164
Joined: Sun Apr 21, 2013 12:55 am


Return to UNO API and ODF

Who is online

Users browsing this forum: No registered users and 2 guests