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:

#!/usr/bin/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.

Thanks,
Dave

Moved to the programming forum (The Gurkha, Moderator).
Open Office 3.1 on Ubuntu 9.10
dtsatwicz
 
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 com.sun.star.beans import UnknownPropertyException
from com.sun.star.lang import ArrayIndexOutOfBoundsException
from com.sun.star.lang import WrappedTargetException
from com.sun.star.uno import RuntimeException
# oInitialTarget is the current document
def snippet(oInitialTarget):
    try:
        # 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
        print(e)
    except ArrayIndexOutOfBoundsException as e:
        # getUserFieldName
        print(e)
    except UnknownPropertyException as e:
        # getPropertyValue
        print(e)
    except RuntimeException as e:
        # getPropertySetInfo, getProperties
        print(e)
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.4
User avatar
Villeroy
Volunteer
 
Posts: 28168
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 5 guests