Perl OpenOffice::OODoc将段落中的文本样式化
我有一个简单的任务,就是添加一个段落,其中包含一些格式化文本。我搞不懂如何将文本样式化 输出示例:John Smith200 Main Streetsingle 我一直在读关于CPAN的文档 我发现我可以使用textStyle(element[,style])来更改现有元素的样式。我必须先添加文本才能设置样式吗 请参阅文档中的和 下面是一个实现您所需功能的示例:Perl OpenOffice::OODoc将段落中的文本样式化,perl,openoffice.org,cpan,Perl,Openoffice.org,Cpan,我有一个简单的任务,就是添加一个段落,其中包含一些格式化文本。我搞不懂如何将文本样式化 输出示例:John Smith200 Main Streetsingle 我一直在读关于CPAN的文档 我发现我可以使用textStyle(element[,style])来更改现有元素的样式。我必须先添加文本才能设置样式吗 请参阅文档中的和 下面是一个实现您所需功能的示例: use OpenOffice::OODoc; my $doc = odfDocument(file=> 'outputfile.
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;
当我看到它是这样写的时候,这是非常有意义的。非常感谢。您知道列出所有可用属性(如fo:font-weight和fo:font-style)的资源吗?请查看规范:
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;