Get a list of all User Fields

Keyboard macros or custom scripts

Get a list of all User Fields

Postby dtsatwicz » Wed Mar 03, 2010 11:41 pm

I would like to have an application retrieve a list of all User Fields (Defined by the sequence of: Click Insert, Fields, Other, Type: User Field) in an Open Office text document.

Through perl CPAN OpenOffice::OODoc routines I am able to get and change the value of a User Field in the ODT file provided that I know the name of the field(s) in advance, which I do not. I would like to be able to ask the document for a list of all of the User Fields that it contains.

What is the function or method call sequence that will return a list of User Fields (preferably used within the document as distinguished from those defined but not used) in an Open Office Text Document?

Although I used perl, I will appreciate a solution in any language.

For example, in perl:

use OpenOffice::OODoc;
my $doc = odfDocument (file => "my-file.odt");

# The following method call works
my $data = $doc->userFieldValue ("fieldname");

# What I would like is, but does not exist, or I don't know how to code it
my @fieldnames = $doc->userFieldNames();

Any Ideas?

Any help will be appreciated.


Moved to the programming forum (The Gurkha, Moderator).
Open Office 3.1 on Ubuntu 9.10
Posts: 1
Joined: Wed Mar 03, 2010 11:02 pm

Re: Get a list of all User Fields

Postby Villeroy » Thu Mar 04, 2010 12:31 am

I used the MRI extension to browse a document's object hierarchy and recorded som code in the Python language:

Code: Select all   Expand viewCollapse view
from import UnknownPropertyException
from import ArrayIndexOutOfBoundsException
from import WrappedTargetException
from import RuntimeException
# oInitialTarget is the current document
def snippet(oInitialTarget):
        # DocumentProperties are depricated
        oDocumentProperties = oInitialTarget.DocumentProperties
        oUserDefinedProperties = oDocumentProperties.UserDefinedProperties
        oPropertySetInfo = oUserDefinedProperties.getPropertySetInfo()
        oProperties = oPropertySetInfo.getProperties()

        # this is the new stuff:
        oDocumentInfo = oInitialTarget.DocumentInfo
        oPropertyValues = oDocumentInfo.PropertyValues
        nUserFieldCount = oDocumentInfo.getUserFieldCount()
        sUserFieldName = oDocumentInfo.getUserFieldName( 0 )
    except WrappedTargetException as e:
        # getPropertyValue
    except ArrayIndexOutOfBoundsException as e:
        # getUserFieldName
    except UnknownPropertyException as e:
        # getPropertyValue
    except RuntimeException as e:
        # getPropertySetInfo, getProperties
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
Posts: 29713
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Return to OpenOffice Basic, Python, BeanShell, JavaScript

Who is online

Users browsing this forum: No registered users and 3 guests