Contenido

# Servicio SFDocuments.Writer

The SFDocuments shared library provides a number of methods and properties to facilitate the management and handling of LibreOffice documents.

Some methods are generic for all types of documents and are inherited from the SF_Document module, whereas other methods that are specific for Writer documents are defined in the SF_Writer module.

## Invocación del servicio

Antes de utilizar el servicio Writer, es necesario cargar o importar la biblioteca ScriptForge:

• Para cargar la biblioteca ScriptForge que necesitan las macros de Basic se debe usar la siguiente declaración:
GlobalScope.BasicLibraries.loadLibrary("ScriptForge")
• Los scripts de Python necesitan importar el módulo scriptforge:
from scriptforge import CreateScriptService

The Writer service is closely related to the UI service of the ScriptForge library. Below are a few examples of how the Writer service can be invoked.

##### En BASIC

The code snippet below creates a Writer service instance that corresponds to the currently active Writer document.

        Dim oDoc As Object
        Set oDoc = CreateScriptService("SFDocuments.Writer", "Untitled 1") ' Default = ActiveWindow

Another way to create an instance of the Writer service is using the UI service. In the following example, a new Writer document is created and oDoc is a Writer service instance:

        Dim ui As Object, oDoc As Object
        Set ui = CreateScriptService("UI")
        Set oDoc = ui.CreateDocument("Writer")

Or using the OpenDocument method from the UI service:

        Set oDoc = ui.OpenDocument("C:\Me\MyFile.odt")

It is also possible to instantiate the Writer service using the CreateScriptService method:

        Dim oDoc As Object
        Set oDoc = CreateScriptService("SFDocuments.Writer", "MyFile.odt")

En el ejemplo anterior, «MyFile.odt» es el nombre de la ventana de un documento abierto. Si este argumento no se provee, se considera la ventana activa.

Es recomendable liberar recursos después del uso:

        Set oDoc = oDoc.Dispose()

However, if the document was closed using the CloseDocument method, it becomes unnecessary to free resources using the command described above.

##### En Python

        myDoc = CreateScriptService("Writer") ' Default = ActiveWindow

        ui = CreateScriptService("UI")
        myDoc = ui.CreateDocument("Writer")

        myDoc = ui.OpenDocument(r"C:\Documents\MyFile.odt")

        myDoc = CreateScriptService("SFDocuments.Writer", "MyFile.odt")
        myDoc.Dispose()

El uso del prefijo «SFDocuments.» al llamar el servicio es facultativo.

## Definiciones

## Propiedades

## Métodos

Lista de métodos en el servicio Writer
Forms | PrintOut | …

## Forms

En función de los parámetros provistos, este método devolverá:

- A zero-based Array (or a tuple in Python) with the names of all the forms contained in the document (if the form argument is absent)

- A SFDocuments.Form service instance representing the form specified as argument.

This method is applicable only for Writer documents. Calc and Base documents have their own Forms method in the Calc and Base services, respectively.

### Sintaxis:

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

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

svc.Forms(form: int): svc

### Parámetros:

form: The name or index corresponding to a form stored in the document. If this argument is absent, the method will return a list with the names of all forms available in the document.

### Ejemplo:

In the following examples, the first line gets the names of all forms in the document and the second line retrieves the Form object of the form named "Form_A".

##### En BASIC

        Set FormNames = oDoc.Forms()
        Set FormA = oDoc.Forms("Form_A")

##### En Python

        form_names = doc.Forms()
        form_A = doc.Forms("Form_A")

## PrintOut

Send the contents of the document to the printer. The printer may be previously defined by default, by the user or by the SetPrinter method of the Document service. Returns True when successful.

### Sintaxis:

svc.PrintOut(opt pages: str = "", opt copies: num = 1, opt printbackground: bool = True, opt printblankpages: bool = False, opt printevenpages: bool = True, opt printoddpages: bool = True, opt printimages: bool = True): bool

### Parámetros:

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

copies: The number of copies, default is 1.

printbackground: Prints the background image when True (default).

printblankpages: When False (default), omits empty pages.

printevenpages: Prints even pages when True (default).

printoddpages: Print odd pages when True (default).

printimages: Print graphic objects when True (default).

### Ejemplo:

##### En BASIC

          oDoc.PrintOut("1-4;10;15-18", Copies := 2, PrintImages := False)

##### En Python

        doc.PrintOut(printblankpages = True, copies = 3)

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

Servicio SFDocuments.Document

Servicio ScriptForge.UI