incubator-odf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Uwe Bosecker" <>
Subject Update VariableField doesn't work
Date Mon, 14 May 2012 11:04:16 GMT
Hi there,

my intention is to manipulate some OpenOffice Text Document (.odt) files.
I try to do this using simple-odf-0.7-incubating.jar 
and Java 1.6.0_24 (Eclipse Indigo, Windows 7).

The documents are prepared and pre-filled, no additional text has to be 
added. The odt-files contain bookmarks and some variable fields.
These bookmarks or fields may either be empty or initialized with some 
strings, date, numeric values ...

I just want to manipulate the values of some fields and leave the rest of 
the document untouched.

So I used the following code sample to load an odt-file with some pages and
different variable fields, one of them called "NumVar", and tried to change
the numeric value of this field using the getVariableFieldByName(..)-method
and the updateField(..)-method. Finally I saved the file.

    public static void main(String[] args) {
        try {
            TextDocument doc = TextDocument.loadDocument("resource/sample.odt");
            VariableField field = doc.getVariableFieldByName( "NumVar" );
            OdfElement elem = doc.getContentRoot();
            field.updateField("123", elem);

        } catch (Exception e) {

The odt-file could be loaded successfully, VariableField was found,
updateField-method passed without exception, but the resulting sample2-file
has not been "changed", means the value of "NumVar" is the same as before.

I suppose the error is in:
            OdfElement elem = doc.getContentRoot();
            field.updateField("123", elem);

Which OdfElement-instance has to be used
Seems ContextRoot isn't the right one!?

And one more question: can odftoolkit/simple-odf handle bookmarks too?

Thanks for any help.

P.S.: I tried the cookbook-sample (8.1.1) and it worked,
but I do not need any additional text or paragraph.

NEU: FreePhone 3-fach-Flat mit kostenlosem Smartphone!                                  
Jetzt informieren:

View raw message