OpenOffice-OODoc - Re: new version to create empty odt file and modify style properties

Posted on Fri Sep 15 17:46:15 2006 by jmgdoc in response to 3039 (See the whole thread of 4)
Re: new version to create empty odt file and modify style properties

I've several suggestions, the first is minor, the others more important.

First, the sequence of "use OpenOffice::OODoc::Xyz" is useless. As soon as the main module (OpenOffice::OODoc) is loaded, all the submodules are loaded, so you could remove 8 lines from "use OpenOffice::OODoc::File" to "use OpenOffice::OODoc::XPath".

Second: the really displayed name of the "Quotations" style through OpenOffice.org is out of our control, because "Quotations" is the name of a predefined style, and it's translated according to your local installation. You should try another style name; for example, "Kuotations" is displayed as is.

Third: In the appendParagraph() instruction, the style option is set with "Text body" (the display name), but "Text_20_body" (the internal name) should be used instead.

Last: In your script, the physical file (test.odt) is loaded separately through $content and $style. As a consequence, the last instruction
$content->save("test.odt")
overwrites the changes previously committed by
$style->save("test.odt")
The script works nevertheless, because the file is saved and reopened after every intermediate update, but it generates a lot of useless I/O traffic and XML parsing (remember that, with a complex document, ooDocument() is a very costly operation).
You should explicitly link the two instances in the beginning of the program this way:
$content = ooDocument ( file => "test.odt, member => "content", create => "text ); $style = ooDocument ( file => $content, member => "styles" );
Then you should call the save() method, at the very end, from either $content or $style (at your choice, but only once).
Direct Responses: 3088 | Write a response