SFDocuments.Base service

The Base service provides a number of methods and properties to facilitate the management and handling of LibreOffice Base documents.

Ez a szolgáltatás szorosan kapcsolódik a Document szolgáltatáshoz, amely általános módszereket biztosít a LibreOffice dokumentumok kezeléséhez, beleértve a Base dokumentumokat is. Ezért a Base szolgáltatás kibővíti a Document szolgáltatást, és további, a Base dokumentumokra jellemző metódusokat biztosít, lehetővé téve a felhasználók számára, hogy:

tip

Refer to the Document service to learn more about methods and properties that can be used to manage LibreOffice documents.


A szolgáltatás igénybevétele

Before using the Base 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 Base service can be invoked in a variety of ways. The code snippet below uses the method CreateBaseDocument from the UI service to create a new Base file.

Note that in all examples the object oDoc is an instance of the Base service.


    Dim ui As Object, oDoc As Object
    Set ui = CreateScriptService("UI")
    Set oDoc = ui.CreateBaseDocument("C:\Documents\MyFile.odb")
  

The Base service can also be instantiated while opening an existing Base file, as shown below:


    Set oDoc = ui.OpenBaseDocument("C:\Documents\MyFile.odb")
  

If a Base document is already open, it is possible to instantiate the Base service directly:


    Dim oDoc As Object
    Set oDoc = CreateScriptService("SFDocuments.Document", "MyFile.odb")
  
A Python nyelvben

The examples above can be translated to Python as follows:


    from scriptforge import CreateScriptService
    ui = CreateScriptService("UI")
    doc = ui.CreateBaseDocument(r"C:\Documents\MyFile.odb")
  

    doc = ui.OpenBaseDocument(r"C:\Documents\MyFile.odb")
  

    doc = CreateScriptService("SFDocuments.Document", "MyFile.odb")
  
note

The use of the "SFDocuments." substring in the previous example is optional.


List of Methods in the Base Service

CloseFormDocument
FormDocuments
Forms
GetDatabase

IsLoaded
OpenFormDocument
OpenQuery
OpenTable

PrintOut
SetPrinter



CloseFormDocument

Closes the given form document. Returns True if closure is successful.

warning

A CloseFormDocument metódus a LibreOffice 7.6 óta elavult. Bár továbbra is elérhető, egy későbbi kiadásban eltávolításra kerülhet a Base szolgáltatásból. Használja helyette a CloseDocument metódust a FormDocument szolgáltatásból.


Szintaxis:

svc.CloseFormDocument(formdocument: str): bool

Paraméterek:

formdocument: The name of the FormDocument to be closed, as a case-sensitive string.

Példa:

If form documents are organized in folders, it is necessary to include the folder name to specify the form document to be opened, as illustrated in the following examples:

A Basic nyelvben

    oDoc.CloseFormDocument("Folder1/myFormDocument")
  
A Python nyelvben

    doc.CloseFormDocument('Folder1/myFormDocument')
  

FormDocuments

Returns an array with the full names (path/name) of all form documents in the Base document as a zero-based Array of strings.

Szintaxis:

svc.FormDocuments(): str[0..*]

Példa:

The code snippet below prints the names of all form documents in the current Base document.

A Basic nyelvben

    Dim oDoc as Object, myForms as Object, formName as String
    Set oDoc = CreateScriptService("Document", ThisDataBaseDocument)
    Set myForms = oDoc.FormDocuments()
    For Each formName In myForms
        MsgBox formName
    Next formName
  
A Python nyelvben

    bas = CreateScriptService("Basic")
    doc = CreateScriptService("Document", bas.ThisDataBaseDocument)
    myForms = doc.FormDocuments()
    for formName in myForms:
        bas.MsgBox(formName)
  
tip

To learn more about form documents, refer to the Form service help page.


Forms

Depending on the parameters provided this method will return:

warning

A Forms metódus a LibreOffice 7.6 óta elavult. Bár továbbra is elérhető, egy későbbi kiadásban eltávolításra kerülhet a Base szolgáltatásból. Használja helyette a Forms metódust a FormDocument szolgáltatásból.


Szintaxis:

svc.Forms(formdocument: str): str[0..*]

svc.Forms(formdocument: str, form: str = ''): svc

svc.Forms(formdocument: str, form: int): svc

Paraméterek:

formdocument: The name of a valid form document as a case-sensitive string.

form: Az űrlap-dokumentumban tárolt űrlap neve vagy indexszáma. Ha ez az argumentum hiányzik, a metódus egy listát ad vissza, amely az űrlap-dokumentumban elérhető összes űrlap nevét tartalmazza.

note

Bár az űrlapokra való hivatkozáshoz indexszámokat is lehet használni, ez csak akkor ajánlott, ha az űrlapdokumentumban csak egy űrlap van. Ha két vagy több űrlap van, akkor inkább az űrlap nevét kell használni.


Példa:

Az alábbi példa első sora a "myFormDocument" űrlapdokumentumban található összes űrlap listáját adja vissza. A második sor a Form szolgáltatás egy példányát adja vissza, amely az "myForm" űrlapot képviseli.

A Basic nyelvben

    Dim formsList as Object : formsList = oDoc.Forms("myFormDocument")
    Dim oForm as Object : oForm = oDoc.Forms("myFormDocument", "myForm")
  
A Python nyelvben

    formsList = doc.Forms("myFormDocument")
    form = doc.Forms("myFormDocument", "myForm")
  

GetDatabase

Returns an instance of the Database service that allows the execution of SQL commands on the database defined and/or stored in the current Base document

Szintaxis:

svc.GetDatabase(user: str = '', password: str = ''): svc

Paraméterek:

user, password: Optional login parameters as strings. The default value for both parameters is an empty string "".

Példa:

A Basic nyelvben

    Dim myDoc As Object, myDatabase As Object, ui As Object
    Set ui = CreateScriptService("UI")
    Set myDoc = ui.OpenBaseDocument("C:\Documents\myDb.odb")
    ' User and password are supplied below, if needed
    Set myDatabase = myDoc.GetDatabase()
    '   ... Run queries, SQL statements, ...
    myDatabase.CloseDatabase()
    myDoc.CloseDocument()
  
A Python nyelvben

    ui = CreateScriptService("UI")
    myDoc = ui.OpenBaseDocument(r"C:\Documents\myDb.odb")
    myDatabase = myDoc.GetDatabase()
    #   ... Run queries, SQL statements, ...
    myDatabase.CloseDatabase()
    myDoc.CloseDocument()
  

IsLoaded

Returns True if the specified FormDocument is currently open.

Szintaxis:

svc.IsLoaded(formdocument: str): bool

Paraméterek:

formdocument: The name of a FormDocument to be checked, as a case-sensitive string.

Példa:

A Basic nyelvben

    If Not oDoc.IsLoaded("myFormDocument") Then
        oDoc.OpenFormDocument("myFormDocument")
    End If
  
A Python nyelvben

    if not doc.IsLoaded("myFormDocument"):
        doc.OpenFormDocument("myFormDocument")
  

OpenFormDocument

Opens the specified FormDocument either in normal or in design mode. This method returns a FormDocument service instance corresponding to the specified form document.

If the form document is already open, it is activated without changing its mode.

If the specified form document does not exist, then Nothing is returned.

Szintaxis:

svc.OpenFormDocument(formdocument: str, designmode: bool = False): svc

Paraméterek:

formDocument: The name of the FormDocument to be opened, as a case-sensitive string.

designmode: If this argument is True the FormDocument will be opened in design mode.

Példa:

A Basic nyelvben

Most form documents are stored in the root of the Base document and they can be opened simply using their names, as in the example below:


    Dim oFormDoc As Object
    oFormDoc = oDoc.OpenFormDocument("myFormDocument")
  

If form documents are organized in folders, it becomes necessary to include the folder name to specify the form document to be opened, as illustrated in the following example:


    oFormDoc = oDoc.OpenFormDocument("myFolder/myFormDocument")
  
A Python nyelvben

    formDoc = doc.OpenFormDocument("myFormDocument")
  

    formDoc = doc.OpenFormDocument("myFolder/myFormDocument")
  

OpenQuery

Opens the Data View window of the specified query and returns an instance of the Datasheet service.

The query can be opened either in normal or design mode.

If the query is already open, its Data View window will be made active.

note

Closing the Base document will cause the Data View window to be closed as well.


Szintaxis:

svc.OpenQuery(queryname: str, designmode: bool = False): obj

Paraméterek:

queryname: The name of an existing query as a case-sensitive String.

designmode: If this argument is set to True the query is opened in design mode. Otherwise it is opened in normal mode (Default = False).

Példa:

A Basic nyelvben

      oDoc.OpenQuery("MyQuery", DesignMode := True)
    
A Python nyelvben

      doc.OpenQuery("MyQuery", designmode=True)
    

OpenTable

Opens the Data View window of the specified table and returns an instance of the Datasheet service.

The table can be opened either in normal or design mode.

If the table is already open, its Data View window will be made active.

note

Closing the Base document will cause the Data View window to be closed as well.


Szintaxis:

svc.OpenTable(tablename: str, designmode: bool = False): obj

Paraméterek:

tablename: The name of an existing table as a case-sensitive String.

designmode: If this argument is set to True the table is opened in design mode. Otherwise it is opened in normal mode (Default = False).

Példa:

A Basic nyelvben

      oDoc.OpenTable("MyTable", DesignMode = False)
    
A Python nyelvben

      doc.OpenTable("MyTable", designmode=False)
    

PrintOut

This method sends the content of the given form document to a default printer or a printer defined by the SetPrinter() method.

Returns True if the document was successfully printed.

warning

A PrintOut metódus a LibreOffice 7.6 óta elavult. Bár továbbra is elérhető, egy későbbi kiadásban eltávolításra kerülhet a Base szolgáltatásból. Használja helyette a PrintOut metódust a FormDocument szolgáltatásból.


Szintaxis:

svc.PrintOut(opt formdocument: str, pages: str = "", copies: num = 1): bool

Paraméterek:

formdocument: A valid document form name as a case-sensitive string. The form document must be open. It is activated by the method.

pages: The pages to print as a string, like in the user interface. Example: "1-4;10;15-18". Default is all pages.

copies: The number of copies. Default is 1.

Példa:

A Basic nyelvben

    If oDoc.PrintOut("myForm", "1-4;10;15-18", Copies := 2) Then
        ' ...
    End If
  
A Python nyelvben

    if doc.PrintOut('myForm', copies=3, pages='45-88'):
        # ...
  

SetPrinter

Define the printer options for a form document. The form document must be open.

Returns True when successful.

warning

A SetPrinter metódus a LibreOffice 7.6 óta elavult. Bár továbbra is elérhető, egy későbbi kiadásban eltávolításra kerülhet a Base szolgáltatásból. Használja helyette a SetPrinter metódust a FormDocument szolgáltatásból.


Szintaxis:

svc.SetPrinter(opt formdocument: str, opt printer: str, opt orientation: str, paperformat: str): bool

Paraméterek:

formdocument: A valid document form name as a case-sensitive string.

printer: The name of the printer queue where to print to. When absent, the default printer is set.

orientation: Either PORTRAIT or LANDSCAPE. When absent, left unchanged with respect to the printer settings.

paperformat: Specifies the paper format as a string value that can be either A3, A4, A5, LETTER, LEGAL or TABLOID. Left unchanged when absent.

Példa:

A Basic nyelvben

    oDoc.SetPrinter("myForm", Orientation := "PORTRAIT")
  
A Python nyelvben

    doc.SetPrinter('myForm', paperformat='TABLOID')
  
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!