Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scripting OpenOffice Forms with VB or python

I'm trying to script my OpenOffice document (Writer in my case) to do some simple things with widgets. Namely I'd like to copy text from widget to widget. For this I want to get one component and than get text from it.

I've been trying to do sth like this:

document   = ThisComponent.CurrentController.Frame

oDocument      =  ThisComponent
oTextBoxFrom = document.getByName("Text Box 1")    # 1
oTextBoxFrom = oDocument.getByName("Text Box 1")   # 2

Neither version #1 nor #2 work. VB compiler spits out that "Text Box 1" is not accessible, however I have that component in my form. My guess is that I'm trying to get this component from a wrong place, eg. not it's frame. I just can't figure out what is the structure of the document.

This seems like a pretty easy task, however I'm unable to find any OpenOffice specification as for accessing OO UNO objects from VB, or python.

like image 705
Marcin Cylke Avatar asked Jul 21 '10 06:07

Marcin Cylke


2 Answers

Good day.

if you choose use a VB, you must know this:

VBA : Compatibility between OpenOffice.org Basic and VBA relates to the OpenOffice.org Basic language as well as the runtime library. The OpenOffice.org API and the Dialog Editor are not compatible with VBA (standardizing these interfaces would have made many of the concepts provided in OpenOffice.org impossible).

if it will be python:

OpenOffice.org 3.1 ships with the Python scripting language, version 2.6.1. Older OpenOffice.org ships with Python version 2.3.4. This Python distribution comes with the Uno module, which connects the UNO API to the python scripting language. To run this version of Python on Linux, you can go directly to the OpenOffice.org PATH. And as one would expect with any distribution of Python, OOo-Python can be run from the command line as well. If you already have a separate Python 2.6 installation, you can import the uno module (the Python-UNO bridge) to it using these instructions. If you already have a different version of Python installed on Windows, you can also access the UNO API using the COM bridge instead of the Python bridge. Requires the add-on pywin32 module so Python can talk to COM. Note that while the UNO API is uniform, the implementation by the two bridges is slightly different, so the syntax required by each is also sometimes different.

Python UNO bridge

upd: ooobloger might help you with understanding of python and uno integration.

like image 59
Dmitry Zagorulkin Avatar answered Oct 28 '22 06:10

Dmitry Zagorulkin


i don't have experience with openoffice scripting but i found thes examples, note they never use getByName on the document itself but always on some part of it.

docCalc = ThisComponent
maFeuille = docCalc.Sheets.getByName("leCSV")
....
for f = 0 to lesFamilles.Count -1' chaque famille
nomFam = lesFamilles.ElementNames(f)
uneFamille = lesFamilles.getByName(nomFam)
...
monDocument.TextTables.hasByName("Finances")
...
lesSections = monDocument.TextSections
sectA = lesSections.getByName("Aline")

you can find the rest in this large pdf at http://oqei.free.fr/echange/VBA/Programmation_OpenOffice_org_3_ed1_v1.pdf ,it's in french but code is universal eh ? Hope it helps..

like image 26
peter Avatar answered Oct 28 '22 04:10

peter