21.08.2013 Views

OpenOffice.org BASIC Guide - OpenOffice.org wiki

OpenOffice.org BASIC Guide - OpenOffice.org wiki

OpenOffice.org BASIC Guide - OpenOffice.org wiki

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

5<br />

C H A P T E R 5<br />

5 Working with Documents<br />

The <strong>OpenOffice</strong>.<strong>org</strong> API has been structured so that as many of its parts as possible can be used universally for<br />

different tasks. This includes the interfaces and services for creating, opening, saving, converting, and printing<br />

documents and for template administration. Since these function areas are available in all types of documents,<br />

they are explained first in this chapter.<br />

The StarDesktop<br />

Styles and Templates<br />

The current document<br />

In previous versions of the Basic Programming <strong>Guide</strong> these instructions were used to obtain the current<br />

document :<br />

Dim Doc As Object<br />

Doc = StarDesktop.CurrentComponent<br />

This correct code has a drawback : it does not work if the macro is started from the IDE because it then refers to<br />

the IDE, not the document. This code works only if the macro is started from the document itself!<br />

You should instead use Basic object ThisComponent. It returns the document object on which the macro is run.<br />

If you start the macro from the IDE, ThisComponent will still find and return your document.<br />

Dim Doc As Object<br />

Doc = ThisComponent ' recommended coding for Basic<br />

The StarDesktop<br />

When working with documents, two services are used most frequently:<br />

The com.sun.star.frame.Desktop service, which is similar to the core service of <strong>OpenOffice</strong>.<strong>org</strong>. It provides<br />

the functions for the frame object of <strong>OpenOffice</strong>.<strong>org</strong>, under which all document windows are classified.<br />

Documents can also be created, opened and imported using this service.<br />

The basic functionality for the individual document objects is provided by the<br />

com.sun.star.document.OfficeDocument service. This provides the methods for saving, exporting and<br />

printing documents.<br />

The com.sun.star.frame.Desktop service is created automatically when <strong>OpenOffice</strong>.<strong>org</strong> is started. This service can<br />

be addressed in <strong>OpenOffice</strong>.<strong>org</strong> Basic using the global name StarDesktop.<br />

The most important interface of the StarDesktop is com.sun.star.frame.XComponentLoader. This basically<br />

59

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!