Thread

Posted on Tue May 29 05:18:35 2007 by pauld
Replaceable tokens
Hi all, I'm writing a report script that inserts collected data into various parts of an ODT document. I started off using getUserFieldElement() as the position token, but discovered that they are only useful for simple text replacement (which is useful, but just not the complete solution for me).

Another thing I'm using at the moment is selectElementByBookmark(), which I'm using to insert paragraphs and tables, but unlike user fields there is no visual representation of the bookmark in OpenOffice.

My question is really just a "how would you do it" type question. I'd like to have a situation where the admins who write the report analysis can easily add, remove, or move named tokens in the document that my script can then find and manipulate. Is there any kind of element that is (a)easy for a non-technical person to understand, (b)easy to find one or more occurences (using OODoc), and (c)works well with paragraphs, tables, graphics and other elements.

Thanks for any advice you can give.

Regards, Paul
Direct Responses: 5249 | Write a response
Posted on Tue May 29 13:29:43 2007 by jmgdoc in response to 5247
Re: Replaceable tokens

You could use selectElementByContent() or selectElementsByContent(). These methods allow the application to replace the first occurrence (or all the occurrences) of a given string by a given value.

Alternatively, these methods can be uses in order to trigger (as a callback function) an application-provided subroutine each time an element matching a given regular expression in found. The subroutine can do anything on the element, and/or its return value (if defined) is used as a replacement for the matching substring.

So the user can put some previously agreed, visible tags in the template document, in order to allowing the program to insert any data in the right places. This approach is an efficient substitute to variable fields.

selectElementByContent() and selectElementsByContent() are described in the OpenOffice::OODoc::Text manual page.
Direct Responses: 5263 | Write a response
Posted on Tue May 29 23:23:38 2007 by pauld in response to 5249
Re: Replaceable tokens
Thanks for your suggestions. They would of course work fine, but I'm sure there's a better way. Could we not modify getUserFieldElement to also provide an element or path that works with insertParagraph, insertTable, removeParagraph, etc? Alternately, could it not return an array of paths for each occurrence of the user field value?

With user fields it would be easy for our staff to write document templates without having to learn what is in essence another markup language added on top of what is probably a perfectly adequate feature set built into OpenOffice.org.

Cheers, Paul
Write a response