Open Office Being open source provides you the functionality with which you can customize any tool bar, can assign new tools with some script working over there. That's What i am going to do in my projects. I need to design some sort of script (preferably in python) that let me choose my style of presentation and report with total ease.
Making Tools in OOwriter.
Making new tools is easy in Open Office Writer.
1) Open your OOwriter. Go to Tools->Customize. You will see a window like here:
2) Click On New to make a new toolbar in your open office. And Click on Add to add a new macro, script as a new tool in your tooolbar as shown.After selecting your macro click on add. See below:
3) After that you can assign an icon to newly designed tool and can be modified again & again.
In OOwriter For writing macros there are provided 4 languages:
a) OpenOffice.org Basic
b) Bean Shell
c) Python
d) Javascript as shown:
We can use any of them but preferably i am going to use Python for designing macros so as to customize the selection of styles and formatting in oowriter. But before going in details let me introduce you to python:
Python is a general-purpose high-level programming language whose design philosophy emphasizes code readability. Python aims to combine "remarkable power with very clear syntax", and its standard library is large and comprehensive.
Python supports multiple programming paradigms, primarily but not limited to object oriented, imperative and, to a lesser extent, functional programming styles. It features a fully dynamic type system and automatic memory management, similar to that of Scheme, Ruby, Perl, and Tcl. Like other dynamic languages, Python is often used as a scripting language, but is also used in a wide range of non-scripting contexts.
If you want to go into details of python regarding its syntax and all that
click here.
Using the OpenOffice UNO Bridge
OpenOffice has language bindings for C++, Java, JavaScript and Python. On Windows, OpenOffice can also be manipulated in Pascal via COM Automation (see below), but there is currently no easy way of using OpenOffice's UNO (Universal Network Objects) from Pascal on OS X and Linux but from Python we can easily use it. If you're interested in developing an OO "bridge" for Pascal, please refer to these links for more information (caution: these links are quite techie in true Sun fashion):
>api.openoffice.org
About_Bridges
Attempting to use Python to manipulate OpenOffice
Since OpenOffice includes support for Python, it would seem possible to run Python scripts so as to manipulate OO. Here are the steps for one possible approach to doing this:
1. Test UNO via Python macro run within OO
2. Test UNO via Python standalone script
Step 1. Test UNO via Python macro run within OO
OO has tools for creating JavaScript macros, but not Python macros, so use a text editor to save the following script to file test_macro.py and place it in OO's user macro folder. On Windows, this folder is:
C:\Document and Setting\\Application Data\OpenOffice.org2\user\Scripts\python\Library1
On Mac OS X, this folder is:
~/Library/Preferences/NeoOffice-2.2/user/Scripts/python/Library1
On Linux this folder is:
$ cd \usr\share\openoffice\programs\...
On both platforms, you'll need to create the python/Library1 folder
But no need to create folder in Linux/Unix based system just place script in program folder as mentioned above.
Here is the code for test_macro.py, adapted from the OO Pascal example above:
# Python macro that tests UNO by creating new document and inserting some text.
import uno
def TestNewDoc():
ctx = uno.getComponentContext()
smgr = ctx.ServiceManager
desktop = smgr.createInstance('com.sun.star.frame.Desktop')
doc = desktop.loadComponentFromURL('private:factory/swriter', '_blank', 0, ())
textCursor = doc.Text.createTextCursor()
doc.Text.insertString(textCursor, 'Hello World', 0)
In OO, choose Tools | Macros | Organize Macros | Python and run the macro to make sure it works.
Step 2. Test UNO via Python standalone script
Here is the same code as a standalone script:
# Python script that tests UNO by creating new document and inserting some text.
import sys
if sys.platform == 'darwin':
sys.path.append('/Applications/NeoOffice.app/Contents/MacOS')
import officehelper
ctx = officehelper.bootstrap()
smgr = ctx.ServiceManager
desktop = smgr.createInstance('com.sun.star.frame.Desktop')
doc = desktop.loadComponentFromURL('private:factory/swriter', '_blank', 0, ())
textCursor = doc.Text.createTextCursor()
doc.Text.insertString(textCursor, 'Hello World', 0)
Save this to file test.py and run it like this on Windows from a command line. Note: On Windows and Linux, use the version of Python included with OO; on Mac OS X, use the system's Python 2.3.
"\program files\openoffice.org 2.3\program\python" test.py
On Mac OS X, run the script like this from a Terminal window:
#!/bin/sh
export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH":/Applications/NeoOffice.app/Contents/MacOS"
python2.3 test.py
On Linux
$ python test.py