La biblioteca ScriptForge

Per a accedir a aquesta ordre...

Obriu Eines ▸ Macros ▸ LibreOffice Basic ▸ Edita i seleccioneu el contenidor Macros de l'aplicació.


Les biblioteques ScriptForge formen una col·lecció ampliable de recursos per a crear scripts per al LibreOffice, que es poden invocar a partir de macros BASIC o scripts Python.

note

• Per a carregar macros BASIC cal fer servir la biblioteca ScriptForge mitjançant aquesta expressió:
GlobalScope.BasicLibraries.loadLibrary("ScriptForge")

• Els scripts Python requereixen una importació del mòdul scriptforge:
from scriptforge import CreateScriptService


tip

Per obtenir més informació sobre com podeu crear i executar scripts de Python amb la biblioteca ScriptForge, llegiu la pàgina d'ajuda Creació de Scripts de Python amb ScriptForge.


Invocació dels serveis de l'ScriptForge

Els mòduls i classes descrits s'invoquen a partir d'scripts d'usuari com a «serveis». Amb aquest propòsit, s'ha dissenyat un constructor genèric d'aquests serveis per a cada llenguatge.

El mètode Dispose està disponible en tots els serveis i s'hauria d'invocar per a alliberar de recursos un cop utilitzat:

En Basic

    GlobalScope.BasicLibraries.LoadLibrary("ScriptForge")
    Set oSvc = CreateScriptService("servicename"[, arg0, arg1, ...])
    ' ...
    oSvc.Dispose()
  
En Python

    from scriptforge import CreateScriptService
    svc = CreateScriptService('servicename'[, arg0, arg1, ...])
    # ...
    svc.Dispose()
  

Serveis que forneix la biblioteca ScriptForge

Categoria

Serveis

LibreOffice BASIC

Array
Dictionary

Exception
FileSystem

String
TextStream

Contingut del document

Base
Calc
Chart

Database
Dataset
Datasheet

Document
FormDocument
Writer

Interfície d'usuari

Dialog
DialogControl
Form

FormControl
Menu
PopupMenu

Toolbar
ToolbarButton
UI

Utilitats

Basic
L10N
Platform

Region
Services
Session

Timer
UnitTest


Servei ScriptForge.Array

Provides a collection of methods for manipulating and transforming arrays of one dimension (vectors) and arrays of two dimensions (matrices). This includes set operations, sorting, importing from and exporting to text files.

No es poden utilitzar matrius amb més de dues dimensions amb els mètodes d’aquest servei, l'única excepció és el mètode CountDims que accepta matrius amb qualsevol nombre de dimensions

SFDocuments.Base service

The Base service provides a number of methods and properties to facilitate the management and handling of LibreOffice Base documents.

This service is closely related to the Document service, which provides generic methods for handling LibreOffice documents, including Base documents. Hence, the Base service extends the Document service and provides additional methods that are specific for Base documents, enabling users to:

ScriptForge.Basic service

The ScriptForge.Basic service proposes a collection of LibreOffice Basic methods to be executed in a Python context. Basic service methods reproduce the exact syntax and behaviour of Basic builtin functions.

SFDocuments.Calc service

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

The SFDocuments.Calc service is a subclass of the SFDocuments.Document service. All methods and properties defined for the Document service can also be accessed using a Calc service instance.

The Calc service is focused on:

Servei SFDocuments.Chart

The Chart service provides a set of properties and methods to handle charts in Calc documents. With this service it is possible to:

SFDatabases.Database service

The Database service provides access to databases either embedded or described in Base documents. This service provides methods to:

Servei SFDatabases.Dataset

The Dataset service is used to represent tabular data produced by a database. With this service it is possible to:

Servei SFDatabases.Datasheet

The Datasheet service allows to visualize the contents of database tables as well as the results of queries and SQL statements using Base's Data View. Additionally, this service allows to:

SFDialogs.Dialog service

The Dialog service contributes to the management of dialogs created with the Basic Dialog Editor or dialogs created on-the-fly. Each instance of the current class represents a single dialog box displayed to the user.

SFDialogs.DialogControl service

The DialogControl service manages the controls belonging to a dialog defined with the Basic Dialog Editor. Each instance of the current service represents a single control within a dialog box.

The focus is set on getting and setting the values displayed by the controls of the dialog box. Formatting is accessible via the XControlModel and XControlView properties.

Note that the unique DialogControl.Value property content varies according to the control type.

A special attention is given to controls of type tree control. It is easy to populate a tree, either branch by branch, or with a set of branches at once. Populating a tree control can be performed statically or dynamically.

ScriptForge.Dictionary service

A dictionary is a collection of key-item pairs

SFDocuments.Document service

The SFDocuments library provides methods and properties to facilitate the management and manipulation of LibreOffice documents.

Methods that are applicable for all types of documents (Text Documents, Sheets, Presentations, etc) are provided by the SFDocuments.Document service. Some examples are:

Servei ScriptForge.Exception

The Exception service is a collection of methods to assist in code debugging in Basic and Python scripts and in error handling in Basic scripts.

In Basic scripts, when a run-time error occurs, the methods and properties of the Exception service help identify the error context and allow to handle it.

Servei ScriptForge.FileSystem

The FileSystem service includes routines to handle files and folders. Next are some examples of the features provided by this service:

SFDocuments.Form service

The Form service provides methods and properties to manage forms in LibreOffice documents. This service supports forms in Base, Calc and Writer documents and allows to:

SFDocuments.FormControl service

The FormControl service provides access to the controls that belong to a form, a subform or a table control of a FormDocument. Each instance of the FormControl service refers to a single control in the form. This service allows users to:

SFDocuments.FormDocument service

The FormDocument service allows to access form documents stored in LibreOffice Base documents.

In a Base document, existing form documents can be viewed by selecting View - Forms in the user interface. Each form document may be composed of one or more forms, including the main form and other sub-forms.

Servei ScriptForge.L10N

This service provides a number of methods related to the translation of strings with minimal impact on the program's source code. The methods provided by the L10N service can be used mainly to:

SFWidgets.Menu service

The Menu service can be used to create and remove menus from the menubar of a LibreOffice document window. Each menu entry can be associated with a script or with a UNO command. This service provides the following capabilities:

ScriptForge.Platform service

The Platform service provides a collection of properties about the current execution environment and context, such as:

SFWidgets.PopupMenu service

The PopupMenu service can be used to create popup menus that can be associated with events or executed by scripts. This service provides the following capabilities:

Servei ScriptForge.Region

The Region service provides a collection of properties and methods to handle locale and region-related aspects of programming, such as:

Servei ScriptForge.Services

The main purpose of the Services module is to provide access to the CreateScriptService method, which can be called in user scripts to instantiate services that are implemented using the ScriptForge framework.

ScriptForge.Session service

The Session service gathers various general-purpose methods about:

ScriptForge.String service

The String service provides a collection of methods for string processing. These methods can be used to:

Servei ScriptForge.TextStream

The TextStream service is used to sequentially read from and write to files opened or created using the ScriptForge.FileSystem service.

The methods OpenTextFile and CreateTextFile from the FileSystem service return an instance of the TextStream service.

ScriptForge.Timer service

The Timer service measures the amount of time it takes to run user scripts.

A Timer measures durations. It can be:

SFWidgets.Toolbar service

The Toolbar service allows to retrieve information related to the toolbars available for a specific document window. With this service it is possible to:

SFWidgets.ToolbarButton service

The ToolbarButton service allows to retrieve information related to the toolbar buttons available in a given toolbar. With this service it is possible to:

ScriptForge.UI service

El servei UI (de l'anglès, interfície d'usuari) simplifica la identificació i la manipulació de les diferents finestres que componen l'aplicació LibreOffice:

Servei SFUnitTests.UnitTest

The UnitTest service provides a framework for automating unit tests using the Basic language, including the ability to:

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

Nota: els altres mòduls de l'ScriptForge que no es descriuen aquí estan reservats per a un ús intern. Llurs continguts estan subjectes a canvis sense avís previ.

warning

Totes les rutines o identificadors bàsics de ScriptForge que tenen el prefix de guió baix "_" estan reservats per a ús intern. No estan pensats per utilitzar-los en macros de Basic o scripts de Python.


Ens cal la vostra ajuda!