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.
com.sun.star.lang.XMultiServiceFactory Interface<br />
Overview of Central Interfaces<br />
Context-dependent objects are usually created by means of an object method, on which the object depends. The<br />
createInstance method, which is defined in the XMultiServiceFactory interface, is used in particular in<br />
the document objects.<br />
The drawing object can, for example, be created as follows using a spreadsheet object:<br />
Dim RectangleShape As Object<br />
RectangleShape = _<br />
Spreadsheet.createInstance("com.sun.star.drawing.RectangleShape")<br />
A paragraph template in a text document is created in the same way:<br />
Dim Style as Object<br />
Style = Textdocument.createInstance("com.sun.star.style.ParagraphStyle")<br />
Named Access to Subordinate Objects<br />
The XNameAccess and XNameContainer interfaces are used in objects that contain subordinate objects, which<br />
can be addressed using a natural language name.<br />
While XNamedAccess permits access to the individual objects, XNameContainer takes on the insertion,<br />
modification and deletion of elements.<br />
com.sun.star.container.XNameAccess Interface<br />
An example of the use of XNameAccess is provided by the sheets object of a spreadsheet. It combines all the<br />
pages within the spreadsheet. The individual pages are accessed from the sheets object, by using the getByName<br />
method from XNameAccess:<br />
Dim Sheets As Object<br />
Dim Sheet As Object<br />
Sheets = Spreadsheet.Sheets<br />
Sheet = Sheets.getByName("Sheet1")<br />
The getElementNames method provides an overview of the names of all elements. As a result, it returns a data<br />
field containing the names. The following example shows how all element names of a spreadsheet can thereby be<br />
determined and displayed in a loop:<br />
Dim Sheets As Object<br />
Dim SheetNames<br />
Dim I As Integer<br />
Sheets = Spreadsheet.Sheets<br />
SheetNames = Sheets.getElementNames<br />
For I=LBound(SheetNames) To UBound(SheetNames)<br />
MsgBox SheetNames(I)<br />
Next I<br />
The hasByName method of the XNameAccess interface reveals whether a subordinate object with a particular<br />
name exists within the basic object. The following example therefore displays a message that informs the user<br />
whether the Spreadsheet object contains a page of the name Sheet1.<br />
Dim Sheets As Object<br />
Sheets = Spreadsheet.Sheets<br />
If Sheets.HasByName("Sheet1") Then<br />
MsgBox " Sheet1 available"<br />
Else<br />
MsgBox "Sheet1 not available"<br />
End If<br />
com.sun.star.container.XNameContainer Interface<br />
The XNameContainer interface takes on the insertion, deletion and modification of subordinate elements in a<br />
Chapter 4 · Introduction to the API 55