Monday, November 30, 2009

OpenOffice - Programmatically!

A while ago, I had to parse an XML file and generate a spread sheet out of it.
I could have probably used an XSLT transformation; but as I was learning Python and was dying to try something on XML parsing - took some pain in understanding the format of the XML file and then set out to parse the XML file.
Being new to XML parsing and did not want to go through a lot of trouble, used the xml.dom.minidom parser and finished parsing the XML file.
Now, how did I create the spread sheet? I'll tell ya -
Well, I did not xactly create a spread sheet; instead, I created a simple HTML file with a table structure in it!
Now, all I had to do was to drag and drop the HTML file into an empty OpenOffice spread sheet! and valla..I had my spread sheet ready to be saved in the format of my choice..
However, as any programmer would agree, this is not the most optimised way of doing things and also felt a bit like cheating!
So, I took up the task of creating spread sheets programmatically using OpenOffice and Python. (Java might have been a better choice - but my Java is sorta - pathetic)...
OpenOffice comes with the PyUno module that makes this possible. I'm taking one little baby step at a time in doing this and I'm happy to say - I've started off successfully, creating a very simple and basic spread sheet :).
More on how to and what to do stuff in my next post !
Also, look out for my coming post on Python - GIMP combination and how to reduce the size of your Photography collection - without deleting files and without loosing the quality of the pictures - well, visibly in a few minutes
(I actually already have a shell script, GIMP combination doing this already - very well infact; but want to move this to a proper Python code as GIMP has very strong affinity to Python)