Съдържание

# SFDocuments.Writer service

Споделената библиотека SFDocuments предлага набор от методи и свойства за улесняване управлението и боравенето с документи на LibreOffice.

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.

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

Преди да използвате услугата Writer, библиотеката ScriptForge трябва да бъде заредена или импортирана:

• Макросите на Basic изискват зареждане на библиотеката ScriptForge чрез следния оператор:
GlobalScope.BasicLibraries.loadLibrary("ScriptForge")
• Скриптовете на Python изискват импортиране от модула 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.

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

Или чрез метода OpenDocument на услугата UI:

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

In the example above, "MyFile.odt" is the name of an open document window. If this argument is not provided, the active window is considered.

Препоръчва се ресурсите да бъдат освободени след употреба:

        Set oDoc = oDoc.Dispose()

Ако обаче документът бъде затворен с метода CloseDocument, освобождаването на ресурсите с гореописаната команда става излишно.

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

Използването на префикса "SFDocuments." при извикването на услугата не е задължително.

## Определения

## Свойства

## Методи

List of Methods in the Writer Service
Forms | ImportStylesFromFile | PrintOut

## Forms

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

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

- екземпляр на услугата SFDocuments.Form, представящ зададения като аргумент формуляр.

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

### Синтаксис:

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

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

svc.Forms(form: int): svc

### Параметри:

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.

### Пример:

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

##### В Basic

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

##### В Python

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

## ImportStylesFromFile

This method loads all the styles belonging to one or more style families from a closed file into the actual document. The actual document must be a Calc or a Writer document.

Are always imported together:

- ParagraphStyles and CharacterStyles

- NumberingStyles and ListStyles

Returns True if styles were successfully imported.

### Синтаксис:

svc.ImportStylesFromFile(filename: str, families: str[1..*], overwrite = False): bool

### Параметри:

filename: The file from which to load the styles in the FileSystem notation. The file is presumed to be of the same document type as the actual document.

families: One of the style families present in the actual document, as a case-sensitive string or an array of such strings. Leave this argument blank to import all families.

overwrite: When True, the actual styles may be overwritten. Default is False.

### Пример:

##### В Basic

        oDoc.ImportStylesFromFile("C:\User\Documents\myFile.ods", "ParagraphStyles", True)

##### В Python

        doc.ImportStylesFromFile('C:\User\Documents\myFile.ods', ("ParagraphStyles",), False)

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

### Синтаксис:

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

### Параметри:

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

### Пример:

##### В Basic

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

##### В Python

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

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

Теми, свързани с показаната

SFDocuments.Document service

ScriptForge.UI service

Моля, подкрепете ни!