Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

working with tables in OpenOffice::OODoc

by swathibandaru (Initiate)
on Jun 24, 2016 at 10:58 UTC ( [id://1166483]=perlquestion: print w/replies, xml ) Need Help??

swathibandaru has asked for the wisdom of the Perl Monks concerning the following question:

I have created a table using

$doc = odfDocument(file => 'test.odt', create => 'text'); doc->appendTable(tab1,5,3); doc->cellValue(tab1,0,0,"S No"); doc->cellValue(tab1,0,1,"Name"); doc->cellValue(tab1,0,2,"Value");

In other rows & columns values are added using cellValue.

Requirements: 1. When appendTable is used, table with default settings is created. How to change table Border to dark black with increased thickness 2. Table with all columns of same size is created. I want column 0,2 with less width, column 1 with large width. 3. I want to change Row 0 contents to Bold, as this indicates Heading to table contents.

Unable to find any examples to do above. How to get above requirements. I am trying to create a table in openOffice word document using perl.

Replies are listed 'Best First'.
Re: working with tables in OpenOffice::OODoc
by GotToBTru (Prior) on Jun 24, 2016 at 14:33 UTC

    Not really enough in your post to go on. Can you post enough of your code to show a short, self-contained correct example?

    But God demonstrates His own love toward us, in that while we were yet sinners, Christ died for us. Romans 5:8 (NASB)

Re: working with tables in OpenOffice::OODoc
by poj (Abbot) on Jun 26, 2016 at 06:23 UTC
    see OpenOffice::OODoc::Styles in particular the section
    building styles from scratch by program is not a recommended practice. It's much more easy to create documents which all the needed styles through an ODF-compliant office software, and to use them as templates in the programs, knowing that it's very easy to retrieve an existing style, to copy it and to re-use it (as is or customised) in new documents.
    

    However, for your relatively simple requirements try this

    #!/usr/bin/perl use strict; use OpenOffice::OODoc; my $doc = odfDocument(file => 'test.odt', create => 'text'); $doc->createStyle( "border", family => 'table-cell', parent => 'Standard', properties => { 'fo:border' => "0.05cm solid #000000", 'fo:padding' => "0.05cm", } ); $doc->createStyle( "2cm", family => 'table-column', parent => 'Standard', properties => { 'style:column-width' => "2cm" } ); $doc->createStyle( "6cm", family => 'table-column', parent => 'Standard', properties => { 'style:column-width' => "6cm" } ); $doc->createStyle( "theading", family => 'paragraph', parent => 'Standard', properties => { -area => 'text', 'fo:font-size' => '13pt', 'fo:font-weight' => 'bold', 'fo:color' => '#000000', # black 'fo:font-family' => 'arial', } ); $doc->updateStyle( "theading", properties => { 'fo:background-color' => "#c0c0c0" , # light grey } ); my @width = ('2cm','6cm','2cm'); my @data = ( ['S No','Name','Value'], ['A1','B1','C1'], ['A2','B2','C2'], ['A3','B3','C3'], ['A4','B4','C4'] ); my $table = $doc->appendTable('tab1',5,3); for my $c (0..2){ $doc->columnStyle('tab1',$c,$width[$c]); for my $r (0..4){ $doc->cellStyle('tab1',$r,$c,'border'); $doc->cellValue('tab1',$r,$c,$data[$r][$c]); } $doc->setAttributes($doc->getCellParagraph("tab1",0,$c),'text:style- +name' => 'theading'); } $doc->save;
    poj
      Thanks poj, Its working.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1166483]
Approved by stevieb
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2024-04-19 14:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found