SFDatabases.Datasheet service

The Datasheet service allows to visualize the contents of database tables as well as the results of queries and SQL statements using Base's Data View. Additionally, this service allows to:

A szolgáltatás igénybevétele

Before using the Datasheet service the ScriptForge library needs to be loaded or imported:

note

• Basic macros require to load ScriptForge library using the following statement:
GlobalScope.BasicLibraries.loadLibrary("ScriptForge")

• Python scripts require an import from scriptforge module:
from scriptforge import CreateScriptService


A Basic nyelvben

The Datasheet service can be invoked in two different ways depending on whether the database file is open.

Az alábbi példa úgy tekinti, hogy az adatbázisfájl nyitva van, ezért a UI szolgáltatás használható a dokumentum lekérdezésére, és az OpenTable metódus a Database szolgáltatásból egy Datasheet szolgáltatáspéldány lekérdezésére szolgál.


    Dim ui As Object, oBase As Object, oSheet As Object
    Set ui = CreateScriptService("UI")
    ' Object oBase is an instance of the Base service
    Set oBase = ui.GetDocument("C:\Documents\myDB.odb")
    ' Object oSheet is an instance of the Datasheet service
    Set oSheet = oBase.OpenTable("Customers")
  

In the example above it is also possible to use the method OpenQuery from the Base service to get a Datasheet instance.

A Database szolgáltatás meghívásához, ha az adatbázisfájl nincs megnyitva, használja az OpenTable, OpenQuery vagy OpenSql metódusokat a Database szolgáltatásból. Az alábbi példa az OpenTable metódust használja az adatbázisfájlban meglévő táblázat megnyitásához:


    Dim oDatabase As Object, oSheet As Object
    ' Object oDatabase is an instance of the Database service
    Set oDatabase = CreateScriptService("Database", "C:\Documents\myDB.odb")
    ' Object oSheet is an instance of the Datasheet service
    Set oSheet = oDatabase.OpenTable("Customers")
  
A Python nyelvben

The examples above can be translated to Python as follows:


    from scriptforge import CreateScriptService
    ui = CreateScriptService("UI")
    base_doc = ui.GetDocument(r"C:\Documents\MyFile.odb")
    sheet = base_doc.OpenTable("Customers")
  

    database = CreateScriptService("Database", r"C:\Documents\myDB.odb")
    sheet = database.OpenTable("Customers")
  

Tulajdonságok

The following properties are available in the Datasheet service:

Név

Csak olvasásra

Típus

Leírás

ColumnHeaders

Igen

Array of Strings

Returns an Array with the names of column headers in the datasheet.

CurrentColumn

Igen

String

Returns the currently selected column name.

CurrentRow

Igen

Integer

Returns the number of the currently selected row, starting at 1.

DatabaseFileName

Igen

String

Returns the file name of the Base file in FSO.FileNaming format.

Filter

Nem

String

Megadja az adatlapra alkalmazandó szűrőt, amelyet egy SQL-lekérdezés WHERE záradékaként fejez ki a WHERE kulcsszó nélkül. Ha üres karakterláncot ad meg, akkor az aktív Filter eltávolításra kerül.

LastRow

Igen

Integer

Returns the number of rows in the datasheet.

OrderBy

Nem

String

Megadja a rekordok megjelenítési sorrendjét, az ORDER BY kulcsszó nélküli SQL-lekérdezés ORDER BY záradékaként kifejezve. Ha üres karakterláncot ad meg, akkor az aktív OrderBy megszűnik.

ParentDatabase

Igen

Objektum

Returns the Database service instance to which the datasheet belongs.

Source

Igen

String

Returns a String that represents the data source, which can be a SQL statement, a table name or a query name.

SourceType

Igen

String

Returns the type of the data source, which can be one of the following values: "SQL", "TABLE" or "QUERY".

XComponent

Igen

UNO objektum

Returns the com.sun.star.lang.XComponent UNO object that represents the datasheet.

XControlModel

Igen

UNO objektum

Returns the com.sun.star.awt.XControl UNO object that represents the datasheet.

XTabControllerModel

Igen

UNO objektum

Returns the com.sun.star.awt.XTabControllerModel UNO object that represents the datasheet.


Metódusok

List of Methods in the Datasheet Service

Activate
CloseDatasheet
CreateMenu

GetText
GetValue
GoToCell

RemoveMenu
Toolbars



Activate

Brings to front the data view window referred to by the Datasheet instance.

Szintaxis:

svc.Activate()

Példa:

A Basic nyelvben

      oSheet.Activate()
    
A Python nyelvben

      sheet.Activate()
    

CloseDatasheet

Closes the data view window referred to by the Datasheet instance.

Szintaxis:

svc.CloseDatasheet()

Példa:

A Basic nyelvben

      oSheet.CloseDatasheet()
    
A Python nyelvben

      sheet.CloseDatasheet()
    

CreateMenu

Creates a new menu entry in the data view window and returns a SFWidgets.Menu service instance, with which menu items can be programmatically added.

note

Menus added using the CreateMenu method are lost as soon as the data view window is closed.


Szintaxis:

svc.CreateMenu(menuheader: str, opt before: any, opt submenuchar: str): obj

Paraméterek:

menuheader: The name of the new menu.

előtte: Ez az argumentum lehet egy meglévő menüpont neve, amely elé az új menü kerül, vagy egy szám, amely az új menü pozícióját fejezi ki. Ha ez az argumentum üresen marad, az új menü az utolsó bejegyzésként kerül elhelyezésre.

submenuchar: The delimiter used in menu trees (Default = ">")

Példa:

A Basic nyelvben

      Dim oMenu As Object
      Set oMenu = oSheet.CreateMenu("My Menu", Before := "Data")
      With oMenu
          .AddItem("Item 1", Command := ".uno:About")
          ' ...
          .Dispose()
      End With
    
A Python nyelvben

      menu = sheet.CreateMenu("My Menu", before="Data")
      menu.AddItem("Item 1", command=".uno:About")
      # ...
      menu.Dispose()
    
tip

Read the Menu service help page to learn more about how to create menu and submenu entries and associate commands.


GetText

Returns the text in a given column of the current row.

note

This method does not change the position of the cursor in the data view window.


Szintaxis:

svc.GetText(column: any): str

Paraméterek:

column: The name of the column as a String or the column position (starting at 1). If a position greater than the number of columns is given, the last column is returned.

Példa:

A Basic nyelvben

      oSheet.GetText("FirstName")
    
A Python nyelvben

      sheet.GetText("FirstName")
    

GetValue

Returns the value in a given column of the current row as a valid Basic type.

The types that can be returned are: String, Integer, Long, Single, Double, Date and Null.

Binary types are returned as a Long value indicating the length of the binary field.

An Empty value is returned if the required value could not be retrieved.

note

This method does not change the position of the cursor in the data view window.


Szintaxis:

svc.GetValue(column: any): any

Paraméterek:

column: The name of the column as a String or the column position (starting at 1). If a position greater than the number of columns is given, the last column is returned.

Példa:

A Basic nyelvben

      oSheet.GetValue("Address")
    
A Python nyelvben

      sheet.GetValue("Address")
    

GoToCell

Moves the cursor to the specified row and column.

note

This method does not change the position of the cursor in the data view window.


Szintaxis:

svc.GoToCell(opt row: int, opt column: any): bool

Paraméterek:

sor: A sorszám numerikus értékként, 1-től kezdődően. Ha a kért sor meghaladja a meglévő sorok számát, a kurzor az utolsó sorba kerül. Ha ez az argumentum nincs megadva, akkor a sor nem változik.

oszlop: Az oszlop neve String-ként vagy az oszlop pozíciója (1-től kezdődően). Ha a kért oszlop meghaladja a meglévő oszlopok számát, a kurzor az utolsó oszlopra kerül. Ha ez az argumentum nincs megadva, akkor az oszlop nem változik.

Példa:

A Basic nyelvben

      ' Moves the cursor to the column "LastName" in row 4
      oSheet.GoToCell(4, "LastName")
      ' Moves the cursor to the third column of the current row
      oSheet.GoToCell(Column := 3)
      ' Moves cursor one row down leaving it in the same column
      oSheet.GoToCell(Row := oSheet.CurrentRow + 1)
      ' Moves to the last column of the last row
      Dim LastColumn As Integer : LastColumn = UBound(oSheet.ColumnHeaders) + 1
      oSheet.GoToCell(oSheet.LastRow, LastColumn)
    
A Python nyelvben

      sheet.GoToCell(4, "LastName")
      sheet.GoToCell(column=3)
      sheet.GoToCell(row=sheet.CurrentRow + 1)
      sheet.GoToCell(sheet.LastRow, len(sheet.ColumnHeaders))
    

RemoveMenu

Removes a menu entry from the data view by its name.

note

Ez a módszer eltávolíthatja a standard felhasználói felülethez tartozó menüket, valamint a CreateMenu módszerrel programozottan hozzáadott menüket. A szabványos menük eltávolítása nem végleges, és az ablak bezárása és újbóli megnyitása után újra megjelennek.


Szintaxis:

svc.RemoveMenu(menuheader: str): bool

Paraméterek:

menuheader: The case-sensitive name of the menu to be removed. The name must not include the tilde ("~") character.

Példa:

A Basic nyelvben

      oSheet.RemoveMenu("Data")
    
A Python nyelvben

      sheet.RemoveMenu("Data")
    

Toolbars

This method returns either a list of the available toolbar names in the actual document or an instance SFWidgets.Toolbar service.

Szintaxis:

svc.Toolbars(opt ToolbarName: str): uno
svc.Toolbars(): str[0..]

Paraméterek:

ToolbarName: The usual name of one of the available toolbars.

Példa:

A Basic nyelvben

    Dim oToolbar As Object
    Set oToolbar = oDoc.Toolbars("myToolbar")
  
A Python nyelvben

    a_list = doc.Toolbars()
  
warning

All ScriptForge Basic routines or identifiers that are prefixed with an underscore character "_" are reserved for internal use. They are not meant be used in Basic macros or Python scripts.


Támogasson minket!