Perl OpenOffice::OODoc - accessing header/footer elements

Go To StackoverFlow.com

1

How do you get elements in a header/footer of a odt doc?

for example I have:

use OpenOffice::OODoc;    
my $doc = odfDocument(file => 'whatever.odt');
    my $t=0;
    while (my $table = $doc->getTable($t))
    {
       print "Table $t exists\n";
       $t++;
    }

When I check the tables they are all from the body. I can't seem to find elements for anything in the header or footer?

2012-04-05 01:44
by Myforwik
I don't know the full answer, but I can tell you that if you unzip a .odt file, you'll get a file called 'content.xml'. If you look at the xml (it helps to use xmltidy). This will show you the structure of the odf document. The data structures inside an OpenOffice::OODoc object reflect the xpath structure of the xml. Find the text in your header, read the tags around it, and you should be able to figure out where to look for it in the OODoc object - Barton Chittenden 2012-04-05 02:57
I just looked in the OpenOffice::OODoc::Text perldoc, it states that headers and footers may be defined in "styles.xml" - Barton Chittenden 2012-04-05 03:08


1

I found sample code here which led me to the answer:

#! /usr/local/bin/perl

use OpenOffice::OODoc;

my $file='asdf.odt';

# odfContainer is a representation of the zipped odf file 
# and all of its parts.
my $container = odfContainer("$file");

# We're going to look at the 'style' part of the container,
# because that's where the header is located.
my $style = odfDocument
    (
    container => $container,
    part      => 'styles'
    );

# masterPageHeader takes the style name as its argument.
# This is not at all clear from the documentation.
my $masterPageHeader = $style->masterPageHeader('Standard');
my $headerText = $style->getText( $masterPageHeader );

print "$headerText\n"

The master page style defines the look and feel of the document -- think CSS. Apparently 'Standard' is the default name for the master page style of a document created by OpenOffice... that was the toughest nut to crack... once I found the example code, that fell out in my lap.

2012-04-05 13:05
by Barton Chittenden
Ads