OpenOffice :: OODoc style text in paragraph

I have a simple task to add a paragraph that has some formatted text. I can’t figure out how to style text.

Output Example: 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;

I read the CPAN documentation http://search.cpan.org/~jmgdoc/OpenOffice-OODoc/ I see that I can use textStyle (element [, style]) to change the style of an existing element. Do I have to add text first to its style?

+3
source share
1 answer

See extendText () and setSpan () in the documentation.

, , :

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;
+3

Source: https://habr.com/ru/post/1713558/


All Articles