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-07-05 03:40:44.806545-07 by mcfaq
Create Document via template (*.ott)
Hi. If I create an template with suffix '.ott' in OpenOffice editor and afterwards open it, then Office asks for a new name for the file as expected for template behaviour. The first question is: How can I create a new document with the OO Cpan module with a *.ott template. I read in Doku that a template has a suffix not like *.ott. So I saved the template as normal *.odt Dokument and used it as template. The first problem was, that I have to remove any content in the template before insert new one. This way I want to use predefined named styles for paragraphs and images and lay them out by the style definitions in the template file. But this was not possible. Here is my code:
#!/usr/bin/perl -w use OpenOffice::OODoc; use Data::Dumper; my $cnt = 1; my $par = undef; my $archive = odfContainer('myfile.odt', create => 'text',template_path => "."); my $content = odfDocument ( container => $archive, part => 'content' ); #delete old content from template.odt: #Why there is now way to use template of format .ott and so there would no need to delete any conte +nt ? $content->removeParagraph($content->selectParagraphByStyle('Para1')); $content->removeParagraph($content->selectParagraphByStyle('Para2')); foreach($content->getImageElementList()){ $content->removeElement($_); } ###### First paragraph ######### $par = $content->appendParagraph( style => 'Para1'); $content->setTextSpan( $par, 'Para1_Line1', offset => 'end', text => 'CustomText 1' ); $content->appendLineBreak($par); $content->setTextSpan( $par, 'Para1_Line2', offset => 'end', text => 'CustomText 2' ); $content->createImageElement("picture_" . $cnt++, style => 'pic1', attachment => $par, import => '/ +var/www/pic1.jpg'); ####### Following: Next Paragraph ######### $par = $content->appendParagraph( style => 'Para2'); $content->setTextSpan( $par, 'Para2_Line1', offset => 'end', text => 'CustomText 3' ); $content->appendLineBreak($par); $content->setTextSpan( $par, 'Para2_Line2', offset => 'end', text => 'CustomText 4' ); $content->createImageElement("picture_" . $cnt++, style => 'pic2', attachment => $par, import => '/ +var/www/pic2.jpg'); #### Insert last paragraph #### $par = $content->appendParagraph( text => 'A long long time ago ...', style => 'Para3'); $archive->save();
The template file was named template.odt I want to upload it here also, but I don't know where to store. If anybody wants the files and my resulting outputfile. Please leave your email. Kind regards.
Direct Responses: 13399 | Write a response