Text Documents (Writer)
HTML Documents (Writer Web)
Spreadsheets (Calc)
Presentations (Impress)
Drawings (Draw)
Database Functionality (Base)
Formulae (Math)
Charts and Diagrams
Macros and Scripting
Office Installation
Common Help Topics
OneOffice Logo

The ScriptForge Library

To access this command...

Open Tools - Macros - Office Basic - Edit and select Application Macros container.

ScriptForge libraries build up an extensible collection of macro scripting resources for Office to be invoked from Basic macros or Python scripts.

• 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

To learn more about how to create and execute Python scripts using the ScriptForge library, read the help page Creating Python Scripts with ScriptForge.

Invoking ScriptForge services

The described modules and classes are invoked from user scripts as "Services". A generic constructor of those services has been designed for that purpose for each language.

The Dispose method is available in all services and should be called to free up resources after usage:

In Basic

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

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

Services provided by the ScriptForge library

Category Services
Office Basic Array Dictionary Exception FileSystem String TextStream
Document Content Base Calc Chart Database Document Writer
User Interface Dialog DialogControl Form FormControl Menu PopupMenu UI
Utilities Basic L10N Platform Region Services Session Timer UnitTest

ScriptForge.Array service

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.

Arrays with more than two dimensions cannot be used with the methods in this service, the only exception being the CountDims method that accepts Arrays with any number of dimensions.

SFDocuments.Base service

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

This service is closely related to the Document service, which provides generic methods for handling Office 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:

  • Get access to the database contained in a Base document.
  • Open form documents stored in a Base document.
  • Check if a form document from a Base document is currently loaded.

ScriptForge.Basic service

The ScriptForge.Basic service proposes a collection of Office 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 Office 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:

  • Handling sheets within a Calc document (copy, insert, move, etc)
  • Exchanging data between Basic data structures and Calc ranges
  • Copying and importing massive amounts of data

SFDocuments.Chart service

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

  • Access chart objects in Calc documents and manipulate their properties.
  • Create and insert new charts into a Calc document.
  • Export charts as image files.

SFDatabases.Database service

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

  • Get access to data in database tables.
  • Run SELECT queries and perform aggregate functions.
  • Run SQL action statements such as INSERT, UPDATE, DELETE, etc.

SFDialogs.Dialog service

The Dialog service contributes to the management of dialogs created with the Basic Dialog Editor. Each instance of the current class represents a single dialogue 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 dialogue 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

  • The key is a case-insensitive string
  • Items may be of any type

SFDocuments.Document service

The SFDocuments library provides methods and properties to facilitate the management and manipulation of Office 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:

  • Opening, closing and saving documents
  • Accessing standard or custom properties of documents

ScriptForge.Exception service

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.

ScriptForge.FileSystem service

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

  • Verify whether a file or folder exists.
  • Create and delete folders and files.
  • Launch dialog boxes to open/save files.
  • Access the list of files in a folder, etc.

SFDocuments.Form service

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

  • Open and activate forms.
  • Navigate through records shown by the form.
  • Get access to the controls inside the form.
  • Get access to subforms of a parent form.

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:

  • Get and set the properties of the control represented by the FormControl instance.
  • Access the current value displayed by the control.
  • Set the focus on the desired control.

ScriptForge.L10N service

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:

  • Create POT files that can be used as templates for translation of all strings in the program.
  • Get translated strings at runtime for the language defined in the Locale property.

SFWidgets.Menu service

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

  • Creation of menus with custom entries, checkboxes, radio buttons and separators.
  • Decoration of menu items with icons and tooltips.

ScriptForge.Platform service

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

  • The hardware platform (architecture, CPU count, machine type, etc)
  • Operating system information (OS type, release, version, etc)
  • The Office version
  • The current user name

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:

  • Creation of popup menus with custom entries, checkboxes and radio buttons.
  • Decoration of menu items with icons and tooltips.

ScriptForge.Region service

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

  • Accessing locale and region-dependent settings such as number formatting, currency and timezones.
  • Converting timezones and calculate Daylight Saving Time (DST) offsets.
  • Transforming numbers into text in any supported language.

ScriptForge.Services service

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:

  • the installation or execution environment
  • UNO introspection
  • the invocation of external scripts or programs

ScriptForge.String service

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

  • Validate the contents of strings
  • Format strings by trimming, justifying or wrapping their contents
  • Use regular expressions to search and replace substrings
  • Apply hash algorithms on strings, etc.

ScriptForge.TextStream service

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:

  • Started, to indicate when to start measuring time.
  • Suspended, to pause measuring running time.
  • Resumed, to continue tracking running time after the Timer has been suspended.
  • Restarted, which will cancel previous measurements and start the Timer at zero.

ScriptForge.UI service

The UI (User Interface) service simplifies the identification and the manipulation of the different windows composing the whole Office application:

  • Windows selection
  • Windows moving and resizing
  • Statusbar settings
  • Display of a floating progress bar
  • Creation of new windows
  • Access to the underlying "documents"

SFUnitTests.UnitTest service

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

  • Aggregate test cases into test suites and unit tests.
  • Share setup and shutdown code among test cases.
  • Report test results using the Console.

SFDocuments.Writer service

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

Note: Other ScriptForge undescribed modules are reserved for internal use. Their content is subject to change without notice.

All ScriptForge Basic routines or identifiers that are prefixed with an underscore character "-" are reserved for internal use. They are not meant be used in Basic macros or Python scripts.