Услуга SFDatabases.Datasheet

Услугата Datasheet позволява визуализиране съдържанието на таблици в база от данни, както и резултатите от заявки и оператори на SQL, посредством прозореца „Изглед с данни“ на Base. Освен това чрез нея е възможно:

Извикване на услугата

Преди да използвате услугата Datasheet, библиотеката ScriptForge трябва да бъде заредена или импортирана:

note

• Макросите на Basic изискват зареждане на библиотеката ScriptForge чрез следния оператор:
GlobalScope.BasicLibraries.loadLibrary("ScriptForge")

• Скриптовете на Python изискват импортиране от модула scriptforge:
from scriptforge import CreateScriptService


В Basic

Услугата Datasheet може да бъде извикана по два различни начина според това дали е отворен файл на база от данни.

В примера по-долу се приема, че файлът на базата от данни е отворен, следователно услугата UI може да се използва за извличане на документа, а методът OpenTable от услугата Database – за получаване на екземпляр на услугата Datasheet.


    Dim ui As Object, oBase As Object, oSheet As Object
    Set ui = CreateScriptService("UI")
    ' Обектът oBase е екземпляр на услугата Base.
    Set oBase = ui.GetDocument("C:\Documents\myDB.odb")
    ' Обектът oSheet е екземпляр на услугата Datasheet.
    Set oSheet = oBase.OpenTable("Customers")
  

В горния пример е възможно и да се използва методът OpenQuery от услугата Base, за да се получи екземпляр на услугата Datasheet.

За да извикате услугата Datasheet, когато базата от данни не е отворена, използвайте метода OpenTable, OpenQuery или OpenSql от услугата Database. В примера по-долу е използван методът OpenTable, за да се отвори съществуваща таблица във файла на базата от данни:


    Dim oDatabase As Object, oSheet As Object
    ' Обектът oDatabase е екземпляр на услугата Database.
    Set oDatabase = CreateScriptService("Database", "C:\Documents\myDB.odb")
    ' Обектът oSheet е екземпляр на услугата Datasheet.
    Set oSheet = oDatabase.OpenTable("Customers")
  
В Python

Примерите по-горе могат да бъдат преведени на Python както следва:


    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")
  

Свойства

В услугата Datasheet са налични следните свойства:

Име

Само за четене

Тип

Описание

ColumnHeaders

Да

Масив от низове

Връща масив (Array) със заглавията на колоните в листа с данни.

CurrentColumn

Да

String

Връща името на текущо избраната колона.

CurrentRow

Да

Integer

Връща номера на текущо избрания ред, започвайки от 1.

DatabaseFileName

Да

String

Връща името на файла на Base във формата, зададен с FSO.FileNaming.

Filter

Не

String

Указва филтър, който да се приложи върху листа с данни, изразен като клауза WHERE от заявка на SQL без ключовата дума WHERE. Ако е зададен празен низ, активният Filter се премахва.

LastRow

Да

Integer

Връща броя редове в листа с данни.

OrderBy

Не

String

Указва реда, в който да се показват записите, изразен като клауза ORDER BY на заявка на SQL без ключовите думи ORDER BY. Ако е зададен празен низ, активният OrderBy се премахва.

ParentDatabase

Да

Обект

Връща екземпляра на услугата Database, към който принадлежи листът с данни.

Source

Да

String

Връща низ, представящ източника на данни, който може да бъде оператор на SQL, име на таблица или име на заявка.

SourceType

Да

String

Връща типа на източника на данни, който може да бъде една от следните стойности: "SQL", "TABLE" или "QUERY".

XComponent

Да

UNO обект

Връща UNO обекта от типа com.sun.star.lang.XComponent, който представя листа с данни.

XControlModel

Да

UNO обект

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

XTabControllerModel

Yes

UNO Object

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


Methods

List of Methods in the Datasheet Service

Activate
CloseDatasheet
CreateMenu

GetText
GetValue

GoToCell
RemoveMenu


Activate

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

Синтаксис:

svc.Activate()

Пример:

В Basic

      oSheet.Activate()
    
В Python

      sheet.Activate()
    

CloseDatasheet

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

Синтаксис:

svc.CloseDatasheet()

Пример:

В Basic

      oSheet.CloseDatasheet()
    
В Python

      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.


Синтаксис:

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

Параметри:

menuheader: The name of the new menu.

before: This argument can be either the name of an existing menu entry before which the new menu will be placed or a number expressing the position of the new menu. If this argument is left blank the new menu is placed as the last entry.

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

Пример:

В Basic

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

      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.


Синтаксис:

svc.GetText(column: any): str

Параметри:

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.

Пример:

В Basic

      oSheet.GetText("FirstName")
    
В Python

      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.


Синтаксис:

svc.GetValue(column: any): any

Параметри:

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.

Пример:

В Basic

      oSheet.GetValue("Address")
    
В Python

      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.


Синтаксис:

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

Параметри:

row: The row number as a numeric value starting at 1. If the requested row exceeds the number of existing rows, the cursor is moved to the last row. If this argument is not specified, then the row is not changed.

column: The name of the column as a String or the column position (starting at 1). If the requested column exceeds the number of existing columns, the cursor is moved to the last column. If this argument is not specified, then the column is not changed.

Пример:

В Basic

      ' 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)
    
В Python

      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

This method can remove menus that belong to the standard user interface as well as menus that were programmatically added with the CreateMenu method. The removal of standard menus is not permanent and they will reappear after the window is closed and reopened.


Синтаксис:

svc.RemoveMenu(menuheader: str): bool

Параметри:

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

Пример:

В Basic

      oSheet.RemoveMenu("Data")
    
В Python

      sheet.RemoveMenu("Data")
    
warning

В ScriptForge всички подпрограми или идентификатори на Basic с префикс „_“ са запазени за вътрешна употреба. Те не са предназначени за използване в макроси на Basic.