Contenido
Índice 🔎︎

# Servicio SFDocuments.Base

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.

## Invocación del servicio

##### En BASIC

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.

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

##### En Python

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

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

Lista de métodos en el servicio Base
CloseFormDocument FormDocuments Forms | GetDatabase IsLoaded OpenFormDocument | PrintOut SetPrinter

## CloseFormDocument

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

### Sintaxis:

svc.CloseFormDocument(formdocument: str): bool

### Parámetros:

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

### Ejemplo:

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:

##### En BASIC

        oDoc.CloseFormDocument("Folder1/myFormDocument")

##### En Python

        doc.CloseFormDocument('Folder1/myFormDocument')

## FormDocuments

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

### Sintaxis:

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

### Ejemplo:

El fragmento de código que verá a continuación muestra los nombres de todos los formularios en el documento de Base actual.

##### En 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

##### En Python

        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 the Form service help page.

## Forms

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)

- A SFDocuments.Form object representing the form specified in the Form argument.

### Sintaxis:

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

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

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

### Parámetros:

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

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.

### Ejemplo:

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".

##### En BASIC

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

##### En 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

### Sintaxis:

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

### Parámetros:

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

### Ejemplo:

##### En BASIC

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

##### En Python

        ui = CreateScriptService("UI")
        myDoc = ui.OpenBaseDocument(r"C:\Documents\myDb.odb")
        myDatabase = myDoc.GetDatabase()
        '   … Ejecute consultas, instrucciones SQL, etc.
        myDatabase.CloseDatabase()
        myDoc.CloseDocument()

## IsLoaded

Returns True if the specified FormDocument is currently open.

### Sintaxis:

svc.IsLoaded(formdocument: str): bool

### Parámetros:

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

### Ejemplo:

##### En BASIC

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

##### En Python

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

## OpenFormDocument

Abre el FormDocument especificado, bien en modo normal, bien en modo de diseño.

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.

### Sintaxis:

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

### Parámetros:

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.

### Ejemplo:

##### En BASIC

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:

        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:

        oDoc.OpenFormDocument("myFolder/myFormDocument")

##### En 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.

### Sintaxis:

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

### Parámetros:

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.

### Ejemplo:

##### En BASIC

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

##### En 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.

### Sintaxis:

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

### Parámetros:

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.

### Ejemplo:

##### En BASIC

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

##### En Python

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

Todas las rutinas o identificadores BASIC de ScriptForge precedidas por guion bajo «_» están reservadas para uso interno. No deben utilizarse en macros BASIC o secuencias Python.

Temas relacionados

SFDatabases.Database service

Servicio SFDocuments.Document

SFDocuments.Form service

Servicio ScriptForge.UI