Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenOffice::OODoc stylize text within a paragraph

I have a simple task of adding a paragraph that has some formatted text within it. I cannot figure out how to stylize the text.

Example output: 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've been reading the documentation on CPAN 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 first add text in order to style it?

like image 533
ojreadmore Avatar asked Nov 21 '25 01:11

ojreadmore


1 Answers

Please see extendText() and setSpan() in the Documentation.

Here is an example that does what you want:

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;
like image 173
Inshallah Avatar answered Nov 24 '25 09:11

Inshallah



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!