A simple script for ODF files
<p>
<strong>Solution</strong>: Luckily they are ODF files, ODF is a zipped XML, a <a href="http://search.cpan.org/dist/OpenOffice-OODoc/OODoc.pod">PERL module</a> exists to do incredible tricks.
</p>
<p>
I have then made this basic script, just tweaking the example provided:
</p>
<pre>
#/bin/perl! #filename to be passed as an argument use OpenOffice::OODoc;
# get global access to the content of an ODF file
my $document = odfDocument(file => $ARGV[0] );
# select a text element containing a given string
my $place = $document->getParagraph(0);
# insert a new text element before the selected one
my $newparagraph = $document->insertParagraph
(
$place,
position => 'before',
text => 'A COOL new paragraph to be inserted
at the beginning of the file',
style => 'Text body'
);
# save the modified document
$document->save;
<p>
I know it is slightly less than a hack, but do that with a MSÂ Word document.
</p>
<p>
Installing the module is pretty straightforward, it only requires an additional module to manage zip files, as dependancy, on my Ubuntu 10.10 standard PERL installation.
</p>
<p>
Many Thanks to <strong>Ingolf Schaefer</strong> (@<a href="mailto:ovidius@identi.ca">ovidius@identi.ca</a>) for the hints. Also <strong>Giuseppe Maxia</strong> pointed in the right direction.
</p>
</div>
<div class="field-item odd">
<a href="/taxonomy/term/37">InteroperabilitĂ </a>
</div>