Servizio SFDocuments.Base

Il servizio Base fornisce numerosi metodi e proprietà per facilitare la gestione e la manipolazione dei documenti di LibreOffice Base.

Questo servizio è strettamente connesso al servizio Document, che fornisce metodi generici per manipolare documenti di LibreOffice, compresi quelli di Base. Perciò, il servizio Base estende il servizio Document e fornisce metodi aggiuntivi specifici per i documenti di Base, consentendo all'utente di:

tip

Fate riferimento a Servizio Document per imparare di più sui metodi e le proprietà da utilizzare per gestire i documenti di LibreOffice.


Invocare il servizio

In Basic

Il servizio Base può essere invocato in diversi modi. Il frammento di codice sottostante usa il metodo CreateBaseDocument del servizio UI per creare un nuovo file di Base.

Fate attenzione che in tutti gli esempi l'oggetto oDoc è un'istanza del servizio Base.


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

Il servizio Base può essere istanziato anche aprendo un file di Base esistente, come mostrato qui sotto:


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

Se un documento di Base è già aperto, è possibile istanziare il servizio Base direttamente:


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

Gli esempi qui sopra possono essere portati in Python come segue:


    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

L'uso della sottostringa "SFDocuments." dell'esempio precedente è opzionale.


Elenco dei metodi del servizio Base

CloseFormDocument
FormDocuments
Forms

GetDatabase
IsLoaded
OpenFormDocument

PrintOut
SetPrinter


CloseFormDocument

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

Sintassi:

svc.CloseFormDocument(formdocument: str): bool

Parametri:

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

Esempio:

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:

In Basic

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

    doc.CloseFormDocument('Folder1/myFormDocument')
  

FormDocuments

Restituisce una matrice con i nomi completi (percorso/nome) di tutti i formulari del documento di Base. La matrice inizia con indice zero e contiene stringhe.

Sintassi:

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

Esempio:

Il frammento di codice sottostante stampa i nomi di tutti i formulari del documento corrente di Base.

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

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

Per saperne di più sui formulari, fate riferimento alle pagine di aiuto del servizio Form.


Forms

A seconda dei parametri forniti questo metodo restituirà:

Sintassi:

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

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

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

Parametri:

formdocument: il nome di un documento formulario valido, espresso come stringa che distingue tra maiuscole e minuscole.

form: il nome o il numero indice del formulario memorizzato nel documento formulario. Se l'argomento è assente, il metodo restituirà l'elenco dei nomi di tutti i formulari disponibili nel documento formulario.

note

Anche se è possibile usare il numero indice per fare riferimento ai formulari, questo è raccomandato solo quando nel documento è presente un solo formulario. Se ce ne sono due o più, è preferibile usare invece il nome del formulario.


Esempio:

La prima riga dell'esempio che segue restituisce un elenco dei formulari nel documento formulario "myFormDocument". La seconda riga restituisce un'istanza del servizio Form che rappresenta il formulario "myForm".

In Basic

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

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

GetDatabase

Restituisce un'istanza del servizio Database che permette l'esecuzione di comandi SQL sul database definito e/o memorizzato nel documento di Base corrente

Sintassi:

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

Parametri:

user, password: parametri di accesso opzionali espressi come stringa. Il valore predefinito di entrambi i parametri è una stringa vuota "".

Esempio:

In Basic

    Dim myDoc As Object, myDatabase As Object, ui As Object
    Set ui = CreateScriptService("UI")
    Set myDoc = ui.OpenBaseDocument("C:\Documents\myDb.odb")
    ' Utente e password sono fornite di seguito, se necessarie
    Set myDatabase = myDoc.GetDatabase()
    ' ... Esegue ricerche (query), istruzioni SQL, ...
    myDatabase.CloseDatabase()
    myDoc.CloseDocument()
  
In Python

    ui = CreateScriptService("UI")
    myDoc = ui.OpenBaseDocument(r"C:\Documents\myDb.odb")
    myDatabase = myDoc.GetDatabase()
    ' ... Esegue query, comandi SQL, ...
    myDatabase.CloseDatabase()
    myDoc.CloseDocument()
  

IsLoaded

Restituisce True se il FormDocument specificato è attualmente aperto.

Sintassi:

svc.IsLoaded(formdocument: str): bool

Parametri:

formdocument: il nome di un FormDocument da controllare, espresso come stringa che distingue tra maiuscole e minuscole.

Esempio:

In Basic

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

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

OpenFormDocument

Apre il FormDocument specificato, sia in modo normale sia in modo bozza.

Se il documento formulario è già aperto, viene attivato senza modificare il suo modo. Il metodo restituisce True se il documento formulario può essere aperto.

Sintassi:

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

Parametri:

formDocument: il nome del FormDocument da aprire, espresso come stringa che distingue tra maiuscole e minuscole.

designmode: se questo argomento è True il FormDocument sarà aperto in modo bozza.

Esempio:

In Basic

La maggior parte dei formulari è memorizzata nella radice dei documenti di Base e può essere aperta usando semplicemente il loro nome, come nell'esempio seguente:


    oDoc.OpenFormDocument("myFormDocument")
  

Quando i formulari sono organizzati in cartelle, diventa necessario includere il nome della cartella per specificare il formulario da aprire, come illustrato dal seguente esempio:


    oDoc.OpenFormDocument("myFolder/myFormDocument")
  
In 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.

Sintassi:

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

Parametri:

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.

Esempio:

In Basic

    If oDoc.PrintOut("myForm", "1-4;10;15-18", Copies := 2) Then
        ' ...
    End If
  
In 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.

Sintassi:

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

Parametri:

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.

Esempio:

In Basic

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

    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.