1

如何在 odt 文档的页眉/页脚中获取元素?

例如我有:

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

当我检查表格时,它们都来自身体。我似乎无法在页眉或页脚中找到任何元素?

4

1 回答 1

1

我在这里找到了示例代码,这让我得到了答案:

#! /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"

母版页样式定义了文档的外观和感觉——想想 CSS。显然,“标准”是 OpenOffice 创建的文档的母版页样式的默认名称……这是最难破解的问题……一旦我找到示例代码,它就掉在了我的腿上。

于 2012-04-05T13:05:35.083 回答