De structuur van werkbladdocumenten

From Apache OpenOffice Wiki
< NL‎ | Documentation‎ | BASIC Guide
Revision as of 12:16, 2 March 2013 by DiGro (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Het document-object van een werkbladdocument is gebaseerd op de Elk van deze documenten kan meerdere werkbladen bevatten. In deze gids is een tabel-gebaseerd document of werkbladdocument het gehele document, waar een werkblad (of afgekort: blad ) een werkblad (tabel) in het document is.

Documentation note.png VBA : Voor werkbladdocumenten en hun inhoud wordt in VBA en Apache OpenOffice BASIC een verschillende terminologie gebruikt. Waar het documentobject in VBA een Workbook wordt genoemd en de individuele pagina's Worksheets, worden zij SpreadsheetDocument en Sheet genoemd in Apache OpenOffice BASIC.


U kunt de individuele werkbladen van een werkbladdocument benaderen via de lijst Sheets.

Het volgende voorbeeld toont u hoe u een werkblad kunt benaderen, ofwel via zijn nummer ofwel via zijn naam.

Voorbeeld 1: toegang door middel van het nummer (nummering begint met 0)

Dim Doc As Object
Dim Sheet As Object
Doc = ThisComponent
Sheet = Doc.Sheets (0)


Example 2: access by means of the name

Dim Doc As Object
Dim Sheet As Object
Doc = ThisComponent
Sheet = Doc.Sheets.getByName("Sheet 1")

In the first example, the sheet is accessed by its number (counting begins at 0). In the second example, the sheet is accessed by its name and the getByName method.

The Sheet object that is obtained by the getByName method supports the service. In addition to providing several interfaces for editing the content, this service provides the following properties:

IsVisible (Boolean)
value True if the spreadsheet is visible.
PageStyle (String)
name of the page template for the spreadsheet.

Renaming Sheets

A sheet provides methods getName and setName to read and modify its name. Basic can handle both methods like a property Name. Here we rename the first sheet of the spreadsheet document.

Dim Doc As Object
Dim Sheet As Object
Doc = ThisComponent
Sheet = Doc.Sheets(0)
Sheet.Name = "First"

Creating and Deleting Sheets

The Sheets container of a spreadsheet document is also used to create and delete individual sheets. The following example uses the hasByName method to check if a sheet called MySheet exists. If it does, the method determines a corresponding object reference by using the getByName method and then saves the reference in a variable in Sheet. If the corresponding sheet does not exist, it is created by the createInstance call and inserted in the spreadsheet document by the insertByName method.

Dim Doc As Object
Dim Sheet As Object
Doc = ThisComponent
If Doc.Sheets.hasByName("MySheet") Then
   Sheet = Doc.Sheets.getByName("MySheet")
   Sheet = Doc.createInstance("")
   Doc.Sheets.insertByName("MySheet", Sheet)
End If

The hasByName, getByName and insertByName methods are obtained from the interface as described in Introduction to the API.

The interface provides a better method to create a new sheet: insertNewByName. It inserts a new sheet with the name specified by the first argument, at the position specified by the second argument.

Dim Doc As Object
Doc = ThisComponent
Doc.Sheets.insertNewByName("OtherSheet", 2)

The same interface provides methods moveByName and copyByName.

The interface provides a method to remove a sheet of a given name:

Dim Doc As Object
Doc = ThisComponent

Content on this page is licensed under the Public Documentation License (PDL).
Personal tools