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 2010-07-28 07:09:06.450984-07 by harryc
need to change and ad text in a given frame
use strict; use OpenOffice::OODoc; use OpenOffice::OODoc::Meta; use OpenOffice::OODoc::XPath ; use OpenOffice::OODoc::Image; &test; sub test { my $doc = ooDocument(file => "C:\\macros\\OOSjablonen\\test.odt") ; my $element = getFrameElement('frame_name'); print "el: $element text:\n"; }
gives error: Undefined subroutine &main::getFrameElement called at C:\scripts\test1.pl line 10. what is wrong ?
use strict; use OpenOffice::OODoc; use OpenOffice::OODoc::Meta; use OpenOffice::OODoc::XPath ; use OpenOffice::OODoc::Image; &test; sub test { my $doc = ooDocument(file => "C:\\macros\\OOSjablonen\\test.odt") ; my $element = OpenOffice::OODoc::XPath::getFrameElement('frame_name'); print "el: $element text:\n"; }
gives: Use of uninitialized value $element in concatenation (.) or string at C:\scripts\test1.pl line 11.
does not work either
i work on activestate perl on windows
Thanks for your reply
Direct Responses: 12843 | Write a response
Posted on 2010-07-28 07:43:35.381728-07 by jmgdoc in response to 12842
Re: need to change and ad text in a given frame
This code should never work !
OpenOffice::OODoc is object-oriented. The getFrameElement() method, of course, won't work as long as you don't specify the calling document !!!
You should try with:

$doc->getFrameElement()
Direct Responses: 12844 | Write a response
Posted on 2010-07-28 08:24:32.76618-07 by harryc in response to 12843
Re: need to change and ad text in a given frame
thanks
it was stupid of me
i changed the code and it works ok
now i need to add text that works but somehow i need to set the text Comic Sans Ms 11
my $doc = ooDocument(file => "C:\\macros\\OOSjablonen\\test.odt") ; $element = $doc->getFrameElement('test');; $text = $doc->setText($element,"TEST INSERT TEKST"); $doc->save("C:\\macros\\OOSjablonen\\test1.odt");
How do i change TEST INSERT TEKST to Comic Sans Ms 11
thks
Direct Responses: 12845 | Write a response
Posted on 2010-07-28 09:02:59.824875-07 by jmgdoc in response to 12844
Re: need to change and ad text in a given frame
Ugh.. it's a bit complicated. First, create an appropriate paragraph style with an arbitrary name:
$doc->createStyle( "ComicMS11", family => 'paragraph', parent => "Standard", properties => { -area => 'text', 'style:font-name' => 'Comic Sans MS', 'fo:font-size' => '11pt' } );

Then declare the font. The smartest way consists of importing the font from another document where it's already in use:
$doc2 = odfDocument(file => "foo.odt", part => 'content'); $doc->importFontDeclaration($doc2, "Comic Sans MS");

Otherwise, a brute force XML font declaration must be done.
You can follow the example at OpenOffice::OODoc::Styles::importFontDeclaration

When all this stuff is ready, you can append a paragraph using the new style to the frame:
$doc->appendParagraph( text => "TEST INSERT TEKST", style => "ComicMS11" );
Direct Responses: 12846 | Write a response
Posted on 2010-07-28 11:03:42.496901-07 by harryc in response to 12845
Re: need to change and ad text in a given frame
thks your code works
But I am trying to put a text in a frame
so i tried following code but no success
my $doc = ooDocument(file => "C:\\macros\\OOSjablonen\\test.odt") ; $element = $doc->getFrameElement('test'); $doc->createStyle( "ComicMS11", family => 'frame', parent => "Standard", properties => { -area => 'text', 'style:font-name' => 'Comic Sans MS', 'fo:font-size' => '12pt' } ); $doc->importFontDeclaration($doc, "Comic Sans MS"); $text = $doc->setText($element,"TEST INSERT TEXT"); $doc-> textStyle($element,"ComicMS11"); $doc->save("C:\\macros\\OOSjablonen\\test-out.odt");
what am I doing wrong ?
thks
Direct Responses: 12849 | 12850 | Write a response
Posted on 2010-07-28 14:24:34.989555-07 by jmgdoc in response to 12846
Re: need to change and ad text in a given frame

Your import font declaration can't work; importing a font declaration in a document from the same document doesn't make sens. A font declaration should be imported either from another document or from an application-provided XML string (hardcoded in my example below). In addition, a text style (with given font type and size, say "Comic Sans MS" and "11pt") may apply to a paragraph, not to a frame. So you should append the text to the frame element as a paragraph; this paragraph must be created with the "ComicMS11" style.

For example you could try to replace all that:
$doc->importFontDeclaration($doc, "Comic Sans MS"); $text = $doc->setText($element,"TEST INSERT TEXT"); $doc-> textStyle($element,"ComicMS11");

by that:
$doc->importFontDeclaration ( '<style:font-face ' . 'style:name="Comic Sans MS" ' . 'svg:font-family="Comic Sans MS" />' ); $doc->appendParagraph( attachment => $element, text => "TEST INSERT TEXT", style => "ComicMS11" );
Direct Responses: Write a response
Posted on 2010-07-28 14:59:47.137924-07 by jmgdoc in response to 12846
Re: need to change and ad text in a given frame

Forget my previous answer. There is a simpler and more convenient solution, using setTextBoxContent in order to attach a customized text paragraph to an existing frame.
my $doc = ooDocument(file => "C:\\macros\\OOSjablonen\\test.odt"); # create the needed style $doc->createStyle( "ComicMS11", family => 'frame', parent => "Standard", properties => { -area => 'text', 'style:font-name' => 'Comic Sans MS', 'fo:font-size' => '12pt' } ); # declare the font used by the style $doc->importFontDeclaration( '<style:font-face ' . 'style:name="Comic Sans MS" ' . 'svg:font-family="Comic Sans MS"/>' ); # create a paragraph using this style $paragraph = $doc->createParagraph( "TEST INSERT TEXT", "ComicMS11" ); # use this paragraph as the text # of the target frame $doc->setTextBoxContent('test', $paragraph); $doc->save("C:\\macros\\OOSjablonen\\test-out.odt");
Direct Responses: 12851 | Write a response
Posted on 2010-07-29 01:34:13.843397-07 by harryc in response to 12850
Re: need to change and ad text in a given frame
Thanks
It works like a charm
Did you write OpenOffice-OODoc ?
I love it, nice work
rgds
Harry Conings
Belgium
Direct Responses: Write a response