einen neuen Datenbankbereich erstellen

    From The Document Foundation Wiki
    < Macros‎ | Calc
    This page is a translated version of the page Macros/Calc/ba022 and the translation is 57% complete.


    Other languages:

    Zusammenfassung

    Diese Seite zeigt ein LibreOffice Basic Makro, das einen neuen Datenbankereich mit der Referenz $Tabelle1.$A$1:$F$10 erzeugt. Es ist ein Beispiel aus Kapitel 13 ("Calc als Datenbank") aus dem Handbuch zu Calc 7.0.

    Beschreibung

    In a macro, a database range is created, accessed, and deleted using the DatabaseRanges service. This service has many of the same methods as the NamedRanges service, but lacks the addNewFromTitles method. DatabaseRanges also uses a reduced version of the addNewByName method that lacks arguments for a relative base address and range type

    :

    addNewByName(Name, Bereich)
    Adds a new database range to the current document.

    As an example of creating a range using this method, the macro below creates a database range named MyName and automatically applies auto filters to each of the range’s columns:

    Code

    Sub AddNewDatabaseRange()
      Dim oRange 'Datenbankbereich Objekt
      Dim oAddr  '<span lang="en" dir="ltr" class="mw-content-ltr">Cell address range for the database range.</span>
      Dim oSheet '<span lang="en" dir="ltr" class="mw-content-ltr">First sheet, which will contain the range.</span>
      Dim oDoc   '<span lang="en" dir="ltr" class="mw-content-ltr">Reference ThisComponent with a shorter name.</span>
    
      oDoc = ThisComponent
      If NOT oDoc.DatabaseRanges.hasByName("MyName") Then
        oSheet = ThisComponent.getSheets().getByIndex(0)
        oRange = oSheet.getCellRangeByName("A1:F10")
        oAddr = oRange.getRangeAddress()
        oDoc.DatabaseRanges.addNewByName("MyName", oAddr)
      End If
      oRange = oDoc.DatabaseRanges.getByName("MyName")
      oRange.AutoFilter = True
    End Sub

    Dieses Calc Tabellenblatt enthält den obigen LibreOffice Basic Code..