Ayuda de LibreOffice 24.8
El servicio Base proporciona diversos métodos y propiedades que facilitan la gestión y la manipulación de los documentos de LibreOffice Base.
Este servicio está estrechamente relacionado con el servicio Document, que brinda métodos genéricos para manipular documentos de LibreOffice, incluidos los de Base. De ahí que el servicio Base amplíe Document y ofrezca métodos adicionales específicos para los documentos de Base, permitiendo a los usuarios:
Obtener acceso a la base de datos contenida en un documento de Base.
Abrir los documentos de formulario almacenados en un documento de Base.
Comprobar si un formulario de un documento de Base se encuentra cargado.
Lea la documentación del servicio Document para aprender más acerca de los métodos y las propiedades que pueden utilizarse para manipular documentos de LibreOffice.
Antes de utilizar el servicio Base, es necesario cargar o importar la biblioteca ScriptForge:
El servicio Base se puede invocar de varias formas. El fragmento de código siguiente utiliza el método CreateBaseDocument del servicio UI para crear un archivo nuevo de Base.
Observe que, en todos los ejemplos, el objeto oDoc es un ejemplar del servicio Base.
    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")
  Los ejemplos anteriores pueden expresarse en Python de la siguiente manera:
    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")
  El uso de la subcadena "SFDocuments." en el ejemplo anterior es opcional.
| Lista de métodos en el servicio Base | ||
|---|---|---|
Closes the given form document. Returns True if closure is successful.
The method CloseFormDocument is deprecated since LibreOffice 7.6. Although it is still available, it may be removed from the Base service in a future release. Use the CloseDocument method from the FormDocument service instead.
svc.CloseFormDocument(formdocument: str): bool
formdocument: The name of the FormDocument to be closed, as a case-sensitive string.
Si los documentos de formulario están organizados en carpetas, es necesario incluir el nombre de la carpeta para especificar el documento de formulario que se abrirá, como se ilustra en los siguientes ejemplos:
    oDoc.CloseFormDocument("Folder1/myFormDocument")
  
    doc.CloseFormDocument('Folder1/myFormDocument')
  Devuelve una matriz con los nombres completos (ruta y nombre) de todos los documentos de formulario en el documento de Base en forma de una matriz de cadenas de base cero.
svc.FormDocuments(): str[0..*]
El fragmento de código que verá a continuación muestra los nombres de todos los formularios en el documento de Base actual.
    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
  
    bas = CreateScriptService("Basic")
    doc = CreateScriptService("Document", bas.ThisDataBaseDocument)
    myForms = doc.FormDocuments()
    for formName in myForms:
        bas.MsgBox(formName)
  To learn more about form documents, refer to ScriptForge.FormDocument service help page.
En función de los parámetros provistos, este método devolverá:
A zero-based Array with the names of all the forms contained in a form document (if the Form argument is absent)
Un objeto SFDocuments.Form que representa el formulario especificado en el argumento Form.
The method Forms is deprecated since LibreOffice 7.6. Although it is still available, it may be removed from the Base service in a future release. Use the Forms method from the FormDocument service instead.
svc.Forms(formdocument: str): str[0..*]
svc.Forms(formdocument: str, form: str = ''): svc
svc.Forms(formdocument: str, form: int): svc
formdocument: el nombre de un documento de formulario válido, expresado como cadena que distingue mayúsculas y minúsculas.
form: The name or index number of the form stored in the form document. If this argument is absent, the method will return a list with the names of all forms available in the form document.
Although it is possible to use index numbers to refer to forms, this is only recommended when there is just one form in the form document. If there are two or more forms, it is preferable to use the form name instead.
The first line of the example below returns a list of all forms in the form document "myFormDocument". The second line returns an instance of the Form service representing the form "myForm".
    Dim formsList as Object : formsList = oDoc.Forms("myFormDocument")
    Dim oForm as Object : oForm = oDoc.Forms("myFormDocument", "myForm")
  
    formsList = doc.Forms("myFormDocument")
    form = doc.Forms("myFormDocument", "myForm")
  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 "".
    Dim myDoc As Object, myDatabase As Object, ui As Object
    Set ui = CreateScriptService("UI")
    Set myDoc = ui.OpenBaseDocument("C:\Documents\myDb.odb")
    ' A continuación se proporcionan el usuario y la contraseña, si hicieran falta
    Set myDatabase = myDoc.GetDatabase()
    '   … Ejecute consultas, instrucciones SQL, etc.
    myDatabase.CloseDatabase()
    myDoc.CloseDocument()
  
    ui = CreateScriptService("UI")
    myDoc = ui.OpenBaseDocument(r"C:\Documents\myDb.odb")
    myDatabase = myDoc.GetDatabase()
    #   … Ejecute consultas o instrucciones SQL…
    myDatabase.CloseDatabase()
    myDoc.CloseDocument()
  Devuelve True si el FormDocument especificado está abierto actualmente.
svc.IsLoaded(formdocument: str): bool
formdocument: el nombre de un FormDocument que se debe comprobar, expresado como cadena que distingue entre mayúsculas y minúsculas.
    If Not oDoc.IsLoaded("myFormDocument") Then
        oDoc.OpenFormDocument("myFormDocument")
    End If
  
    if not doc.IsLoaded("myFormDocument"):
        doc.OpenFormDocument("myFormDocument")
  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.
svc.OpenFormDocument(formdocument: str, designmode: bool = False): svc
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.
La mayor parte de los formularios se almacenan en la raíz del documento de Base y pueden abrirse simplemente utilizando sus nombres, como en el ejemplo siguiente:
    Dim oFormDoc As Object
    oFormDoc = oDoc.OpenFormDocument("myFormDocument")
  Si los documentos de formulario se organizan en carpetas, se vuelve necesario incluir el nombre de la carpeta para especificar el documento que se debe abrir, como se ilustra en el ejemplo siguiente:
    oFormDoc = oDoc.OpenFormDocument("myFolder/myFormDocument")
  
    formDoc = doc.OpenFormDocument("myFormDocument")
  
    formDoc = doc.OpenFormDocument("myFolder/myFormDocument")
  Opens the Data View window of the specified query and returns an instance of the Datasheet service.
La consulta puede abrirse tanto en modo normal como en modo de diseño.
If the query is already open, its Data View window will be made active.
Closing the Base document will cause the Data View window to be closed as well.
svc.OpenQuery(queryname: str, designmode: bool = False): obj
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).
      oDoc.OpenQuery("MyQuery", DesignMode := True)
    
      doc.OpenQuery("MyQuery", designmode=True)
    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.
Closing the Base document will cause the Data View window to be closed as well.
svc.OpenTable(tablename: str, designmode: bool = False): obj
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).
      oDoc.OpenTable("MyTable", DesignMode = False)
    
      doc.OpenTable("MyTable", designmode=False)
    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.
The method PrintOut is deprecated since LibreOffice 7.6. Although it is still available, it may be removed from the Base service in a future release. Use the PrintOut method from the FormDocument service instead.
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.
    If oDoc.PrintOut("myForm", "1-4;10;15-18", Copies := 2) Then
        ' ...
    End If
  
    if doc.PrintOut('myForm', copies=3, pages='45-88'):
        # ...
  Define the printer options for a form document. The form document must be open.
Returns True when successful.
The method SetPrinter is deprecated since LibreOffice 7.6. Although it is still available, it may be removed from the Base service in a future release. Use the SetPrinter method from the Document service instead.
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.
    oDoc.SetPrinter("myForm", Orientation := "PORTRAIT")
  
    doc.SetPrinter('myForm', paperformat='TABLOID')