I wanted to build an awesome place for people to discuss module specific issues, but I don't have any more time for this, and there are much better places to discuss Perl-related issues. I'd recommend asking your question on Stack Overflow or on Perl Monks.
If you are looking for a Perl tutorial or Perl-related news, I hope these links will serve you well.
Posted on 2011-02-03 13:25:23.637176-08 by joebury
Creating Styles for OOCalc through perl
I was trying to programmatically create some basic styles for OOCalc. While the styles are created correctly (they show in the Styles box in Calc) none of them has any required properties set (i.e. font face is always set to Arial rather than Times New Roman and there is no bold). What am I doing wrong? The example below shows several calls to styleCreate, none of which works.
#!/usr/bin/perl use strict; use warnings; use OpenOffice::OODoc; my $container = odfContainer( "aaa.ods", create => 'spreadsheet' ); my $doc = odfDocument( container => $container, part => 'content' ); my $styles = odfDocument( container => $container, part => 'styles' ); $doc->expandTable( 0, 40, 40 ); my $idx=0; printf "-- %s --\n", $styles->createStyle ( "style_$idx", "name" => "style_$idx", "family" => 'text', "properties" => { "fo:font-weight" => "bold", "style:font-name" => "Times New Roman", }, ); $idx += 1; printf "-- %s --\n", $styles->createStyle ( "style_$idx", "name" => "style_$idx", "family" => 'table-cell', "properties" => { "fo:font-weight" => "bold", "style:font-name" => "Times New Roman", }, ); $idx += 1; printf "-- %s --\n", $styles->createStyle ( "style_$idx", "name" => "style_$idx", "family" => 'table-cell', "properties" => { "text-properties" => { "fo:font-weight" => "bold", "style:font-name" => "Times New Roman", }, }, ); $idx += 1; printf "-- %s --\n", $styles->createStyle ( "style_$idx", "name" => "style_$idx", "family" => 'table-cell', "properties" => { "font-weight" => "bold", "font-name" => "Times New Roman", }, ); $idx += 1; printf "-- %s --\n", $styles->createStyle ( "style_$idx", "name" => "style_$idx", "family" => 'table-cell', "text-properties" => { "fo:font-weight" => "bold", "style:font-name" => "Times New Roman", }, ); $idx += 1; printf "-- %s --\n", $styles->createStyle ( "style_$idx", "name" => "style_$idx", "family" => 'table-cell', "text-properties" => { "font-weight" => "bold", "font-name" => "Times New Roman", }, ); $idx += 1; printf "-- %s --\n", $styles->createStyle ( "style_$idx", "name" => "style_$idx", "family" => 'table-cell', "style:text-properties" => { "fo:font-weight" => "bold", "style:font-name" => "Times New Roman", }, ); $idx += 1; printf "-- %s --\n", $styles->createStyle ( "style_$idx", "name" => "style_$idx", "family" => 'table-cell', "style:text-properties" => { "font-weight" => "bold", "font-name" => "Times New Roman", }, ); for ( 0 .. $idx ) { my $cell; $cell = $doc->getTableCell(0, 0, $_ ); $doc->updateCell( $cell, "style_$_" ); $doc->style( $cell, "style_$_" ); } $container->save();
Direct Responses: 13186 | Write a response
Posted on 2011-02-07 08:14:33.648264-08 by jmgdoc in response to 13174
Re: Creating Styles for OOCalc through perl

This program doesn't work for several reasons... First: "Times New Roman" is not declared in the target document. A corresponding font face declaration should be provided (in both the styles and content workspaces for more safety). OODoc doesn't presently provide a high-level font face declaration method, but it's possible to import such a declaration from another document or from an XML font spec string; In your current example, the following code should work:
my $xmlfont = '<style:font-face style:name="Times New Roman" ' . 'svg:font-family="Times New Roman" ' . 'style:font-family-generic="roman" style:font-pitch="variable"/>'; $doc->importFontDeclaration($xmlfont); $styles->importFontDeclaration($xmlfont);

Second: The right way to set the text properties of a cell style is the use of the 'area' selector in the 'properties' section.
Every cell style creation in your example should be reworked according to the following template:
printf "-- %s --\n", $styles->createStyle ( "style_$idx", "name" => "style_$idx", "family" => 'table-cell', "properties" => { area => 'text', "font-weight" => "bold", "font-name" => "Times New Roman", }, );

Third: The right instruction to set a cell style is:
$doc->cellStyle($cell, $stylename);

and not:
$doc->style($cell, $stylename);
Direct Responses: Write a response