views:

129

answers:

3

Hello,

I have a heap of Lotus 123 spreadsheets (not written by me) with Lotus Scripts in them doing an awful lot of leg work (moving data from one spreadsheet to another, and other things like that). I am making the consideration of moving it all away from Lotus 98 and going to something a little more open, like OpenOffice.

I was wondering where would be a good place to start learning Scripting OpenOffice 3. Is Python a good route and if so, where can I find working code examples for OOo3? Any strange issues I should be aware of? Should I use another scripting language like Javascript or OOBasic??

What are peoples thought on scripting OpenOffice 3 basically!

Cheers,

Andy

+2  A: 

Starting point

Start here: Python as a macro language

Examples

Use the Python category in the wiki.

Is there a better scripting language?

Python has by far the best syntax. I'd recommend JavaScript and OOBasic only if those two conditions are met:

  1. You already know the language
  2. You need the built-in debugger

With Python, debugging is usually not a big problem, so you won't miss the debugger and it's easier to learn than any other language.

Aaron Digulla
A: 

I looked into this and found surprisingly little documentation on how to use Python as a scripting language. Having said said that, I figured out what I needed, and it works alright for my simple purposes (making a timetable from rows). It even worked great on OS X, considering that OO.o is quite young on that platform. Python is a great language, much nicer than Basic. Here are some things you need to know:

  • Your starting point in the Python script is XSCRIPTCONTEXT, a global variable directly accessible from your script. Thus you can do

    worksheet = XSCRIPTCONTEXT.getDocument().getSheets().getByIndex(0)
    

    The you can do

    worksheet.getCellByPosition(x,y).getString()
    

    or the corresponding setString() to access the cells.

  • On OS X, I had to put the script in $HOME/Library/Application Support/OpenOffice.org/3/user/Scripts/python. Then it's picked up by the macro dialog.

  • put your macro in a function, say def macro and add

    g_exportedScripts = macro,
    

    at the end.

  • To get debug output, I used:

    logfile = os.path.dirname(__file__.replace("file://","").replace("%20"," ")) + "/output.txt"
    sys.stdout = open(logfile, "a", 0) # unbuffered
    

    Then you can use print, which will be output to output.txt in your script's directory.

That should be enough to get you started.

loevborg