Search This Blog

Saturday, May 28, 2011

Embedding Python scripts in your Open Office document.

i am posting about it on my blog even though it has been answered over the open office and python forums a number of times, because, i had a tough time understanding those replies which were very misleading and complicated. So this is one of the simple and easy version which i think would be simple to understand for all.

Share directory for Python macros is /usr/lib/openoffice/share/Scripts/python
as well as ~/.openoffice.org.2.0/user/Scripts/python
while the former allows you to add a macro that would be available to all the users of the system(since Linux is meant for multiuser environment), the latter allows you to add the macros that will be only available to 1 particular user(depending on who's home directry are you in).

Now, it may be possible that you cann't see these directories. well, in that case, you need to create the directory.
i Hope you do know that .openoffice.org would be a hidden type. also, i have seen that the Scripts folder in second case is empty. So, you can just create a directory of name "python" and place your scripts in it.
to make your scripts visible in the macros inside open office, you will have to put the .pyc file in the python folder otherwise it won't show the python script in executable format.
PS> dont forget to make the file executable.
to make the .pyc file from the py file, use the command
python -m compileall filename.py

And do look at the sample code of helloworld place under the /usr/lib/openoffice/share/Scripts/python directory. It will give you a fair Idea about how the macros work inside the open office. It is much more complex than a simple helloworld program of python, because here it is in the form of a Macros rather than a simple python program

NOTE: these fact remains the same in the higher version of open office too. Just the directory under the Home is changed to the subsequent version. eg: ~/.openoffice.org/3/ user/Scripts/python

No comments:

Post a Comment