OpenOffice.org BASIC Guide - OpenOffice.org wiki
OpenOffice.org BASIC Guide - OpenOffice.org wiki
OpenOffice.org BASIC Guide - OpenOffice.org wiki
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
4<br />
C H A P T E R 4<br />
4 Introduction to the API<br />
<strong>OpenOffice</strong>.<strong>org</strong> objects and methods, such as paragraphs, spreadsheets, and fonts, are accessible to<br />
<strong>OpenOffice</strong>.<strong>org</strong> Basic through the <strong>OpenOffice</strong>.<strong>org</strong> application programming interface, or API. Through the API,<br />
for example, documents can be created, opened, modified and printed. The API can be used not only by<br />
<strong>OpenOffice</strong>.<strong>org</strong> Basic, but also by other programming languages, such as Java and C++. The interface between<br />
the API and various programming languages is provided by something called Universal Network Objects<br />
(UNO).<br />
This chapter provides a background on the API. Building on this background, the following chapters will show<br />
how the API can be used to make <strong>OpenOffice</strong>.<strong>org</strong> do what you want it to do.<br />
Universal Network Objects (UNO)<br />
<strong>OpenOffice</strong>.<strong>org</strong> provides a programming interface in the form of the Universal Network Objects (UNO). This is<br />
an object-oriented programming interface which <strong>OpenOffice</strong>.<strong>org</strong> sub-divides into various objects which for their<br />
part ensure program-controlled access to the Office package.<br />
Since <strong>OpenOffice</strong>.<strong>org</strong> Basic is a procedural programming language, several linguistic constructs have had to be<br />
added to it which enable the use of UNO.<br />
To use a Universal Network Object in <strong>OpenOffice</strong>.<strong>org</strong> Basic, you will need a variable declaration for the<br />
associated object. The declaration is made using the Dim instruction (see The Language of <strong>OpenOffice</strong>.<strong>org</strong> Basic).<br />
The Object type designation should be used to declare an object variable:<br />
Dim Obj As Object<br />
The call declares an object variable named Obj.<br />
The object variable created must then be initialized so that it can be used. This can be done using the<br />
createUnoService function:<br />
Obj = createUnoService("com.sun.star.frame.Desktop")<br />
This call assigns to the Obj variable a reference to the newly created object. com.sun.star.frame.Desktop<br />
resembles an object type; however in UNO terminology it is called a service rather than a type. In accordance with<br />
UNO philosophy, an Obj is described as a reference to an object which supports the<br />
com.sun.star.frame.Desktop<br />
service. The service term used in <strong>OpenOffice</strong>.<strong>org</strong> Basic therefore corresponds to the type and class terms used in<br />
other programming languages.<br />
There is, however, one main difference: a Universal Network Object may support several services at the same<br />
time. Some UNO services in turn support other services so that, through one object, you are provided with a<br />
whole range of services. For example, that the aforementioned object, which is based on the<br />
51