8xmoA‖SFDatabases.Datasheet service

CCxPd‖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:

xZtEL‖Service invocation

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

note

gF8D8‖• 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


3aa4B‖In Basic

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

LXxpq‖The example below considers that the database file is open, hence the UI service can be used to retrieve the document and the OpenTable method from the Database service is used to get a Datasheet service instance.


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

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

5usm9‖To invoke the Datasheet service when the database file is not open, use the OpenTable, OpenQuery or OpenSql methods from the Database service. The example below uses the OpenTable method to open an existing table in the database file:


    Dim oDatabase As Object, oSheet As Object
    6dFFb‖' Object oDatabase is an instance of the Database service
    Set oDatabase = CreateScriptService("Database", "C:\Documents\myDB.odb")
    vFEti‖' Object oSheet is an instance of the Datasheet service
    Set oSheet = oDatabase.OpenTable("Customers")
  
BenDd‖In Python

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

xFcX4‖Properties

yaMir‖The following properties are available in the Datasheet service:

uVScA‖Name

o9D7n‖Read-only

ykDW3‖Type

BJ9DV‖Description

ColumnHeaders

ETvvH‖Yes

7Xcpx‖Array of Strings

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

CurrentColumn

AawGx‖Yes

String

XVhow‖Returns the currently selected column name.

CurrentRow

8ph7x‖Yes

Integer

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

DatabaseFileName

h3vRR‖Yes

String

5FdAQ‖Returns the file name of the Base file in FSO.FileNaming format.

Filter

3TyFG‖No

String

Pv5DC‖Specifies a filter to be applied to the datasheet expressed as the WHERE clause of a SQL query without the WHERE keyword. If an empty string is specified then the active Filter is removed.

LastRow

uiSkN‖Yes

Integer

p4e8b‖Returns the number of rows in the datasheet.

OrderBy

ZERuR‖No

String

y8qWp‖Specifies the order in which records are shown expressed as the ORDER BY clause of a SQL query without the ORDER BY keyword. If an empty string is specified then the active OrderBy is removed.

ParentDatabase

BJAwG‖Yes

faBy9‖Object

iCABS‖Returns the Database service instance to which the datasheet belongs.

Source

3AG3X‖Yes

String

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

SourceType

8VKAq‖Yes

String

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

XComponent

bZqAE‖Yes

wxLJ4‖UNO Object

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

XControlModel

vEoc2‖Yes

tCgaA‖UNO Object

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

XTabControllerModel

62EDa‖Yes

7AReG‖UNO Object

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


wfJfa‖Methods

wgVfx‖List of Methods in the Datasheet Service

Activate
CloseDatasheet
CreateMenu

GetText
GetValue
GoToCell

RemoveMenu
Toolbars



Activate

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

FVEx2‖Syntax:

svc.Activate()

EFSA4‖Example:

3aa4B‖In Basic

      oSheet.Activate()
    
BenDd‖In Python

      sheet.Activate()
    

CloseDatasheet

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

FVEx2‖Syntax:

svc.CloseDatasheet()

EFSA4‖Example:

3aa4B‖In Basic

      oSheet.CloseDatasheet()
    
BenDd‖In Python

      sheet.CloseDatasheet()
    

CreateMenu

fStHW‖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

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


FVEx2‖Syntax:

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

WADQ4‖Parameters:

QC9Uh‖menuheader: The name of the new menu.

yVxAC‖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.

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

EFSA4‖Example:

3aa4B‖In Basic

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

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

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


GetText

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

note

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


FVEx2‖Syntax:

svc.GetText(column: any): str

WADQ4‖Parameters:

3qnwN‖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.

EFSA4‖Example:

3aa4B‖In Basic

      oSheet.GetText("FirstName")
    
BenDd‖In Python

      sheet.GetText("FirstName")
    

GetValue

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

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

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

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

note

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


FVEx2‖Syntax:

svc.GetValue(column: any): any

WADQ4‖Parameters:

DwSZS‖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.

EFSA4‖Example:

3aa4B‖In Basic

      oSheet.GetValue("Address")
    
BenDd‖In Python

      sheet.GetValue("Address")
    

GoToCell

ij88V‖Moves the cursor to the specified row and column.

note

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


FVEx2‖Syntax:

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

WADQ4‖Parameters:

CECkE‖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.

4AYCp‖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.

EFSA4‖Example:

3aa4B‖In Basic

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

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

RemoveMenu

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

note

FhSiD‖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.


FVEx2‖Syntax:

svc.RemoveMenu(menuheader: str): bool

WADQ4‖Parameters:

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

EFSA4‖Example:

3aa4B‖In Basic

      oSheet.RemoveMenu("Data")
    
BenDd‖In Python

      sheet.RemoveMenu("Data")
    

Toolbars

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

FVEx2‖Syntax:

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

WADQ4‖Parameters:

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

EFSA4‖Example:

3aa4B‖In Basic

    Dim oToolbar As Object
    Set oToolbar = oDoc.Toolbars("myToolbar")
  
BenDd‖In Python

    a_list = doc.Toolbars()
  
warning

uzETY‖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.