LibreOffice 25.2 Súgó
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.
Before using the Writer service the ScriptForge library needs to be loaded or imported:
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.
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
  A Writer szolgáltatás egy példányának létrehozásának másik módja a UI szolgáltatás használata. A következő példában egy új Writer dokumentum jön létre, és az oDoc egy Writer szolgáltatáspéldány:
    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.
    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()
  The use of the prefix "SFDocuments." while calling the service is optional.
| List of Methods in the Writer Service | ||
|---|---|---|
Depending on the parameters provided this method will return:
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.
svc.Forms(): str[0..*]
svc.Forms(form: str = ''): svc
svc.Forms(form: int): svc
form: A dokumentumban tárolt űrlapnak megfelelő név vagy index. Ha ez az argumentum hiányzik, a metódus egy listát ad vissza a dokumentumban elérhető összes űrlap nevével.
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".
    Set FormNames = oDoc.Forms()
    Set FormA = oDoc.Forms("Form_A")
  
    form_names = doc.Forms()
    form_A = doc.Forms("Form_A")
  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.
    oDoc.ImportStylesFromFile("C:\User\Documents\myFile.ods", "ParagraphStyles", True)
  
    doc.ImportStylesFromFile('C:\User\Documents\myFile.ods', ("ParagraphStyles",), False)
  A dokumentum tartalmának elküldése a nyomtatónak. A nyomtatót alapértelmezés szerint a felhasználó vagy a Document szolgáltatás SetPrinter metódusa előzetesen meghatározhatja. Siker esetén True értéket ad vissza.
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).
      oDoc.PrintOut("1-4;10;15-18", Copies := 2, PrintImages := False)
  
    doc.PrintOut(printblankpages = True, copies = 3)