title: Transferring table styles using OpenOffice::OODoc
body: <p>I'm attempting to copy the formatting of a table from one OpenOffice Writer file to another... I can tell that I'm writing the name of the style to the second document, but not the style data.</p>
  
  <p>I suspect that this has something to do with the <code>'styles'</code> part of the <code>odfContainer</code>, but I'm not clear on how to write this to the second document, especially because when I inspect the <code>$style</code> object in the debugger, it appears to be identical to the <code>$doc</code> object, which has supposedly loaded the <code>'content'</code> part.</p>
  
  <p>Here's what I've got so far...</p>
  
  <pre><code>#! /usr/bin/perl
  
  use warnings;
  use strict;
  
  use OpenOffice::OODoc;
  
  my $file='mytest.odt';
  my $outfile='doc2.odt';
  
  # load input file
  my $container = odfContainer("$file");
  $container-&gt;raw_export("styles.xml");
  my $doc = odfDocument
          (
          container =&gt; $container,
          part      =&gt; 'content'
          );
  
  my $style = odfDocument
          (
          container =&gt; $container,
          part      =&gt; 'styles'
          );
  
  # load output file
  my $container2 = odfContainer( $outfile, create =&gt; 'text' );
  $container2-&gt;raw_import("styles.xml");
  
  my $doc2 = odfDocument
          (
          container =&gt; $container2,
          part      =&gt; 'content'
          );
  
  
  # Load table from 'mytest.odt'
  my $table=$doc-&gt;getTable(0);
  
  # Get style from first cell in $table
  my $headerstyle=$doc-&gt;getStyle( $doc-&gt;getCell($table, 0, 0) );
  
  # Create table in $doc2
  my $newtable=$doc2-&gt;appendTable('newtable', 1, 1, 'table-style' =&gt; $doc-&gt;getStyle($table) );
  
  # Set style of first cell in $newtable to 'Table1.A1'
  $doc2-&gt;cellStyle( $newtable, 0, 0, 'Table1.A1' );
  
  # Write 'doc2.odt' to disk
  $container2-&gt;save;
  </code></pre>
  
  <p>The reason that I'm loading <code>'Table1.A1'</code> as the cell style is that I found the following deep inside <code>$table</code>, when inspecting inside the debugger:</p>
  
  <pre><code>'next_sibling' =&gt; OpenOffice::OODoc::Element=HASH(0x102029250)
     'att' =&gt; HASH(0x102029180)      
        'style:family' =&gt; 'table-cell'  
        'style:name' =&gt; 'Table1.A1'     
     'empty' =&gt; 0                    
     'first_child' =&gt; OpenOffice::OODoc::Element=HASH(0x1020294a0)
        'att' =&gt; HASH(0x102029200)      
           'fo:background-color' =&gt; '#cccccc'
           'fo:border' =&gt; '0.0069in solid #000000'
           'fo:padding-bottom' =&gt; '0in'    
           'fo:padding-left' =&gt; '0.075in'  
           'fo:padding-right' =&gt; '0.075in' 
           'fo:padding-top' =&gt; '0in'       
           'style:vertical-align' =&gt; 'top' 
           'style:writing-mode' =&gt; 'lr-tb' 
  </code></pre>
  
  <p>I know that the attributes match what I'm trying to copy, and I also know from experimentation that the <code>'getStyle'</code> method returns the <code>style::name</code> attribute... I just don't know how to get from setting the <code>style::name</code> attribute using the <code>cellStyle</code> method to actually having the underlying data written in to the new document.</p>
  
  <p>Edit:</p>
  
  <p>Unzipping the OpenOffice file, I get several xml files:</p>
  
  <ul>
  <li>settings.xml</li>
  <li>styles.xml</li>
  <li>content.xml</li>
  </ul>
  
  <p>etc.</p>
  
  <p>The <code>'styles'</code> and <code>'content'</code> parts of the <code>OdfContainer</code> correspond to styles.xml and content.xml. Styles.xml is a little like a css file, containing the style information for various header levels of an ODF file. Content.xml also contains style information, much like the css header in an html document.</p>
  
  <p>Here's the style part of content.xml extracted from the odt file (actually one much like it... I didn't save the original). </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;office:document-content&gt;
     ...
     &lt;office:automatic-styles&gt;
      &lt;style:style style:name="Table6" style:family="table" style:master-page-name="First_20_Page"&gt;
        &lt;style:table-properties style:width="6.9208in" style:page-number="auto" table:align="left" style:writing-mode="lr-tb" /&gt;
      &lt;/style:style&gt;
      &lt;style:style style:name="Table6.A" style:family="table-column"&gt;
        &lt;style:table-column-properties style:column-width="1.2729in" /&gt;
      &lt;/style:style&gt;
      &lt;style:style style:name="Table6.B" style:family="table-column"&gt;
        &lt;style:table-column-properties style:column-width="3.2604in" /&gt;
      &lt;/style:style&gt;
      &lt;style:style style:name="Table6.C" style:family="table-column"&gt;
        &lt;style:table-column-properties style:column-width="2.3875in" /&gt;
      &lt;/style:style&gt;
      &lt;style:style style:name="Table6.1" style:family="table-row"&gt;
        &lt;style:table-row-properties style:min-row-height="0.1597in" style:keep-together="true" fo:keep-together="auto" /&gt;
      &lt;/style:style&gt;
      &lt;style:style style:name="Table6.A1" style:family="table-cell"&gt;
        &lt;style:table-cell-properties 
           style:vertical-align="bottom" 
           fo:background-color="#cccccc" 
           fo:padding-left="0.075in" 
           fo:padding-right="0.075in" 
           fo:padding-top="0in" 
           fo:padding-bottom="0in" 
           fo:border-left="0.0069in solid #000000" 
           fo:border-right="none" 
           fo:border-top="0.0069in solid #000000" 
           fo:border-bottom="0.0069in solid #000000" 
           style:writing-mode="lr-tb"&gt;
          &lt;style:background-image /&gt;
        &lt;/style:table-cell-properties&gt;
      &lt;/style:style&gt;
   ...
  </code></pre>
  
  <ul>
  <li>style:name="Table6" describes the style for the current table,</li>
  <li>style:name="Table6.A" describes the style for column A of this table,</li>
  <li>style:name="Table6.A1" describes the style for the cell A1</li>
  </ul>
  
  <p>Doing a raw export of 'content.xml' section of the input file, then a raw import in the output file <em>does</em> transfer data from one file to the other.</p>
  
  <pre><code>#! /usr/local/bin/perl
  
  use warnings;
  use strict;
  
  use OpenOffice::OODoc;
  
  my $infile=$ARGV[0];
  my $outfile='outfile.odt';
  
  my $incontainer = odfContainer( $infile );
  $incontainer-&gt;raw_export("content.xml");
  
  my $outcontainer = odfContainer( $outfile, create =&gt; 'text' );
  $outcontainer-&gt;raw_import("content.xml");
  
  $outcontainer-&gt;save;
  </code></pre>
  
  <p>Running <code>oodoc.pl infile.odt</code>, Then unzipping outfile.odt and inspecting content.xml does show that the style has been successfully transferred:</p>
  
  <pre><code>&lt;style:style style:name="Table1" style:family="table"&gt;
    &lt;style:table-properties style:width="6.925in" table:align="margins" /&gt;
  &lt;/style:style&gt;
  &lt;style:style style:name="Table1.A" style:family="table-column"&gt;
    &lt;style:table-column-properties 
     style:column-width="2.3083in" 
     style:rel-column-width="21845*" /&gt;
  &lt;/style:style&gt;
  &lt;style:style style:name="Table1.A1" style:family="table-cell"&gt;
    &lt;style:table-cell-properties 
        fo:background-color="#cccccc" 
        fo:padding="0.0382in" 
        fo:border-left="0.0007in solid #000000" 
        fo:border-right="none" 
        fo:border-top="0.0007in solid #000000" 
        fo:border-bottom="0.0007in solid #000000"&gt;
      &lt;style:background-image /&gt;
    &lt;/style:table-cell-properties&gt;
  &lt;/style:style&gt;
  </code></pre>
  
  <p>Now that this has been done, I'll need to actually load and use the cell styles in <code>$outcontainer</code>.</p>