Услуга SFDocuments.Base

Услугата Base предоставя методи и свойства за управление и работа с документи на LibreOfficeDev Base.

Тази услуга е тясно свързана с услугата Document, която предоставя общи методи за работа с документи на LibreOfficeDev, включително такива на Base. Следователно услугата Base разширява Document и предлага допълнителни методи, специфични за документите на Base, като позволява на потребителите:

tip

Вижте услугата услугата Document, за да научите повече за методите и свойствата, чрез които се управляват документи на LibreOfficeDev.


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

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


В Basic

Услугата Base може да бъде извикана по няколко начина. Долният програмен откъс използва метода CreateBaseDocument от услугата UI, за да създаде нов файл на Base.

Обърнете внимание, че във всички примери обектът oDoc е екземпляр на услугата Base.


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

Екземпляр на услугата Base може да бъде създаден и чрез отваряне на съществуващ файл на Base, както е показано по-долу:


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

Ако вече има отворен документ на Base, е възможно директно да се създаде екземпляр на услугата Base:


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

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


    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

Употребата на подниза "SFDocuments." в предишния пример не е задължителна.


Списък с методи на услугата Base

CloseFormDocument
FormDocuments
Forms

GetDatabase
IsLoaded
OpenFormDocument

PrintOut
SetPrinter


CloseFormDocument

Затваря дадения документ с формуляри. Връща True, ако затварянето е успешно.

Синтаксис:

svc.CloseFormDocument(formdocument: str): bool

Параметри:

formdocument: името на обекта от типа FormDocument, който да бъде затворен, като чувствителен към регистъра низ.

Пример:

Ако документите са организирани в папки, е необходимо да се включи името на папката, за да се укаже кой документ да бъде отворен, както е показано в следващите примери:

В Basic

    oDoc.CloseFormDocument("Folder1/myFormDocument")
  
В Python

    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.

Синтаксис:

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

Пример:

Програмният откъс по-долу отпечатва имената на всички документи с формуляри в текущия документ на Base.

В Basic

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

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

За да научите повече за документите с формуляри, вижте помощната страница на услугата Form.


Forms

В зависимост от подадените параметри, този метод връща:

Синтаксис:

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

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

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

Параметри:

formdocument: името на валиден документ с формуляри като чувствителен към регистъра низ.

form: името или индексът на формуляр, съхраняван в документа с формуляри. Ако този аргумент отсъства, методът ще върне списък с имената на всички формуляри, налични в документа с формуляри.

note

Макар че е възможно за посочване на формуляри да се използват индексни номера, това се препоръчва само когато в документа с формуляри има един единствен формуляр. Ако има два или повече формуляра, за предпочитане е вместо това да се използва името на формуляра.


Пример:

Първият ред на следващия пример връща списък на всички формуляри в документа с формуляри "myFormDocument". Вторият ред връща екземпляр на услугата Form, който представя формуляра "myForm".

В Basic

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

    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

Синтаксис:

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

Параметри:

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

Пример:

В Basic

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

    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.

Синтаксис:

svc.IsLoaded(formdocument: str): bool

Параметри:

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

Пример:

В Basic

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

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

OpenFormDocument

Opens the specified FormDocument either in normal or in design mode.

If the form document is already open, it is activated without changing its mode. The method returns True if the form document could be opened.

Синтаксис:

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

Параметри:

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.

Пример:

В Basic

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:


    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:


    oDoc.OpenFormDocument("myFolder/myFormDocument")
  
В Python

    doc.OpenFormDocument("myFormDocument")
  

    doc.OpenFormDocument("myFolder/myFormDocument")
  

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.

Синтаксис:

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

Параметри:

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.

Пример:

В Basic

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

    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.

Синтаксис:

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

Параметри:

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.

Пример:

В Basic

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

    doc.SetPrinter('myForm', paperformat='TABLOID')
  
warning

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