3

書式設定されたテキストを含む段落を追加するという簡単なタスクがあります。テキストのスタイルを設定する方法がわかりません。

出力例: John Smith 200 Main Street single

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])を使用して既存の要素のスタイルを変更 できることがわかりました。スタイルを設定するには、最初にテキストを追加する必要がありますか?

4

1 に答える 1

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;
于 2009-07-26T02:00:50.207 に答える