SFDocuments.Writer service

The SFDocuments shared library provides a number of methods and properties to facilitate the management and handling of LibreOfficeDev 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.

Service invocation

Before using the Writer service the ScriptForge library needs to be loaded or imported:

note

• Basic macros require to load ScriptForge library using the following statement:
GlobalScope.BasicLibraries.loadLibrary("ScriptForge")

• Python scripts require an import from scriptforge module:
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")
  

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

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.

It is recommended to free resources after use:


    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.

Σε 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()
  
tip

The use of the prefix "SFDocuments." while calling the service is optional.


Definitions

Properties

Methods

List of Methods in the Writer Service

Forms

PrintOut



Forms

Ανάλογα με τις παραμέτρους που παρέχονται, αυτή η μέθοδος θα επιστρέψει:

note

Αυτή η μέθοδος ισχύει μόνο για έγγραφα Writer. Τα έγγραφα Calc και Base έχουν τη δική τους μέθοδο στις υπηρεσίες Forms στα Calc και Base, αντίστοιχα.


Σύνταξη:

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

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

svc.Forms(form: int): svc

Παράμετροι:

form (φόρμα): Το όνομα ή το ευρετήριο που αντιστοιχεί σε μια φόρμα που είναι αποθηκευμένη στο έγγραφο. Εάν αυτό το όρισμα απουσιάζει, η μέθοδος θα επιστρέψει έναν κατάλογο με τα ονόματα όλων των μορφών που είναι διαθέσιμες στο έγγραφο.

Παράδειγμα:

Στα ακόλουθα παραδείγματα, η πρώτη γραμμή λαμβάνει τα ονόματα όλων των μορφών στο έγγραφο και η δεύτερη γραμμή ανακτά το αντικείμενο Form της φόρμας με το όνομα "Form_A".

Σε Basic

    Set FormNames = oDoc.Forms()
    Set FormA = oDoc.Forms("Form_A")
  
Σε 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.

Σύνταξη:

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

Όλες οι ρουτίνες ή αναγνωριστικά του ScriptForge στη Basic που έχουν το πρόθεμα χαρακτήρα υπογράμμισης "_" δεσμεύονται για εσωτερική χρήση. Δεν προορίζονται να χρησιμοποιηθούν σε μακροεντολές Basic ή σενάρια Python.