OpenOffice :: OODoc样式化段落中的文本

时间:2009-07-26 00:46:22

标签: perl openoffice.org cpan

我有一个简单的任务,即添加一个段落,其中包含一些格式化文本。我无法弄清楚如何设计文本样式。

示例输出:John Smith 200 Main Street

my $doc = odfDocument(file=> 'outputfile.odt',create=> 'text');
$doc->appendParagraph(text => "John Smith 200 Main Street single", style => "optionalParagraphStyle");
$doc->save;

我一直在阅读有关CPAN http://search.cpan.org/~jmgdoc/OpenOffice-OODoc/的文档 我看到我可以使用 textStyle(element [,style])来更改现有元素的样式。我必须先添加文字才能设计样式吗?

1 个答案:

答案 0 :(得分:3)

请参阅文档中的extendText()setSpan()

这是一个做你想做的事的例子:

use OpenOffice::OODoc;
my $doc = odfDocument(file=> 'outputfile.odt',create=> 'text');
$doc->createStyle(
    "strong",
    family     => "text",
    properties => { "fo:font-weight"  => "bold" }
    );
$doc->createStyle(
    "em",
    family     => "text",
    properties => { "fo:font-style"  => "italic" }
    );

my $p = $doc->appendParagraph(text => "", style => "optionalParagraphStyle");
$doc->extendText($p, "John Smith");
$doc->extendText($p, " 200 Main Street", "strong");
$doc->extendText($p, " single", "em");

my $p = $doc->appendParagraph(text => "John Smith 200 Main Street single", style => "optionalParagraphStyle");
$doc->setSpan($p, "200 Main Street", "strong");
$doc->setSpan($p, "single", "em");

$doc->save;