As OpenOffice.org macro programmers develop their scripts they will need to open and close documents; for example they may want to:
- open a Calc file to update a spreadsheet
- open up a Writer file in order to add some text
However, any users of those macros will not want to see lots of documents opening and closing all over their screens - they will just want to run the macros and then see the end result. The solution is, of course, to somehow run the macro without displaying any documents that need to be opened. Therefore this article shows a macro developer how to:
- open a document, but keep it hidden
- close the document once the macro's finished with it
It's worth noting that there are two ways of keeping a document hidden when accessing it from a macro:
- on some versions of Linux it is possible to hide the frame containing the document
- in all macros (whether Windows or Linux) it is possible to set one of the document's property values so that it remains hidden
Using Frames to Keep a Document Hidden
The OpenOffice.org loadComponentFromUrl is used to open documents, and one of the parameters it requires is the name of the frame into which the document is to opened. Normally this is the default "_blank" (for a new frame), but some versions of Linux allow the "_hidden" frame to be used, for example:
However, in many cases "_hidden" is treated the same as "_blank". It is, therefore, more reliable to use the document's property values to hide the file.
Using Property Values to Keep a Document Hidden
As well as the name of the frame, the loadComponentFromUrl method expects an array of property values to be passed to it. In order to hide a document the hidden property value must be included in the array and set to TRUE, for example:
Conclusion
This article has shown just how easy it is to hide an OpenOffice.org document while working on it with a macro; of the two techniques the hidden frame is easier to use but cannot be guaranteed to work with every OpenOffice.org installation; however, whilst the property value method is slightly more complicated to use, it will always work regardless of the version of OpenOffice and won't be affected by the user's choice of Linux or Windows.
Further Reading
OpenOffice Macros: Open, Save and Close a File