Posted on 2007-10-29 17:28:58-07 by ag888
Cell style definition
Pelase help in the investigation of behaviour of the fragment:
use OpenOffice::OODoc; my $doc = ooDocument(file => 'tttsty.odt', create => 'spreadsheet'); my $sheet = $doc->getTable(0, 5, 5); $sty = $doc->createStyle("RRR", parent => 'Default', properties => {'fo:text-align' => 'Right'}); $doc->cellValue($sheet,0,0,"aaa"); $doc->cellStyle($sheet,0,0,"RRR"); $doc->save;
RRR style is not have been saved to the document. What wrong in this script? OODoc version = 2.035
Direct Responses: 6369 | Write a response
Posted on 2007-10-30 20:38:46-07 by ag888 in response to 6361
Re: Cell style definition
I think that a know what this query have as answer the silence only... It turned out, that formatting in ODF spreadsheets - extremely difficult task. And even OODoc cannot be able to do this easily. Problem gone mutate: The question: How to create a syntethic (with cell, paragraph and text properties) style like that?:
<style:style style:name="ce1" style:family="table-cell" style:parent-style-name="Default"> <style:table-cell-properties style:text-align-source="fix" style:repeat-content="false" /> <style:paragraph-properties fo:text-align="end" /> <style:text-properties fo:color="#ff3366" /> </style:style>
The second question: How to order style to be as default cell-style for column?:
<table:table-column table:style-name="co1" table:default-cell-style-name="ce1" />
OODoc pods dont clear these aspects.
Direct Responses: 6371 | Write a response
Posted on 2007-10-31 07:02:45-07 by ag888 in response to 6369
Re: Cell style definition
Here the final of my investigation:
... $sty = $doc->createStyle("RRR", family => 'paragraph', parent => 'Standart', properties => { 'fo:text-align' => 'end', 'fo:color' => '#ff0000' } ); $doc->cellValue($sheet,1,1,"aaa"); #$doc->columnStyle($sheet,1,"Noname1"); # dont works (because Noname1 is the <table-cell +> style but not <table-column>) $doc->cellStyle($sheet,1,1,"Noname1"); # works only ! Noname1 - the style created by hands and +especially placed to OODoc templates #$doc->textStyle($doc->getCellParagraph($sheet,1,1), "Heading"); # cannot use <table-cell> styles ! +? - the ODF lack ? #$doc->setStyle($doc->getCell($sheet,1,1), "Noname1"); # it is acceptable combination of calls ? ...
It seems OpenOffice::OODoc dont leave (in present state?) sufficient facilities to full control of OO documents layout!? May be UNO make grant such things (i.e. full control)? But UNO at now is not fully-usable intended pure Open-Source style (OpenOffice-UNO have to build only with MS development tools)...
Direct Responses: 6372 | 10473 | Write a response
Posted on 2007-10-31 07:12:14-07 by ag888 in response to 6371
Re: Cell style definition
...automatic styles (defined like above "RRR") also cannot be used to cell text formatting because it is impossible to define valuable table-cell style from perl-scipt.
Direct Responses: Write a response
Posted on 2009-04-12 07:02:36-07 by smc in response to 6371
Re: Cell style definition
This is a cell style example.

1) load any fonts you want to use
$styles->importFontDeclaration ( '<style:font-face style:name="Calibri" svg:font-family="Calibri" s +tyle:font-adornments="Regular" style:font-pitch="variable"/>');
2) define style in styles.xml. Note the use of table-cell
$styles->createStyle ( 'DataHeading', family => 'table-cell', parent => 'Default', properties => { -area => 'table-cell', 'display-name' => 'DataHeading', 'fo:background-color' => '#000080', 'fo:border' => "0.002cm solid #000000", 'vertical-align' => "middle", } ); if ($doc->isOpenDocument) { $styles->styleProperties ('DataHeading', -area => 'text', 'fo:color' => odfColor("white"), 'style:font-name' => 'Calibri', 'fo:font-size' => '12pt', 'fo:font-weight' => 'bold' ); $styles->styleProperties ('DataHeading', -area => 'paragraph', 'fo:text-align' => 'center' # start (left), center, end (right) ); }
This code will set a spreadsheet table column width:
1) Create style in main document (context.xml, not styles.xml)
$doc->createStyle ( 'ColW2', family => 'table-column', properties => { -area => 'table-column', 'fo:break-before' => 'auto', 'column-width' => '2cm' } );
2) apply
# Set column widths, columns are numbered beginning at 0. $doc->columnStyle($sheet, 0, 'ColW2');

I am far from an opendoc expert, but after lots of trial and error and some tips from the documentation, I did get these snippets working in a spreadsheet.
Direct Responses: Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.