Which way is best to execute a Python script in Excel?

Terry Reedy tjreedy at udel.edu
Thu Jul 5 23:20:20 CEST 2012


On 7/5/2012 5:12 AM, Thomas Jollans wrote:
> On 07/05/2012 09:26 AM, Karim wrote:
>> Look at PyUNO from OpenOffice very large API:
>> http://www.openoffice.org/api/docs
>>
>> I use to create all my documention (Excell, Writer, etc...) on this API.
>
> Note that this API is for OpenOffice, not Microsoft Excel. However, as
> you probably know, you can open most Excel files in OpenOffice's Calc.
>
> I urge you to consider LibreOffice, a fork of OpenOffice that is now
> broadly considered its successor. Its API can also be used in Python
> http://api.libreoffice.org/

Can you explain or point to a document that explains how to actually do 
that? (use the LibreOffice api from Python?)

The only mention of Python on that page is under examples. (and there is 
no mention of python in the installation guide, even as an option, nor 
in the development tools doc, ).

On the example page, there is only one example and unlike all the other 
sections, no 'Additional information' linking to a 'Python Language 
binding'.

In toolpanel.py of the example, there is

import uno
import unohelper

from com.sun.star.ui import XUIElementFactory
from com.sun.star.ui import XUIElement
from com.sun.star.ui.UIElementType import TOOLPANEL as unoTOOLPANEL
from com.sun.star.ui import XToolPanel

but where are the python-importable modules and com package and their 
docs and how does one get them? There are not in the example directory.

The IDL reference only covers the com.sun.star stuff.

---
Looking with Google, I see that some linux distros include 
LibreOffice-PyUno in thier package managers. Not helpful for Windows.

The LibreOffice installation includes a python2.6.1 installation under 
LO.../program/ with pyuno pre-installed. No doc that I could see. 
However, when running it

 >>> import com.sun.star.ui
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
ImportError: No module named com.sun.star.ui

Oh, there is a trick to it
 >>> import uno
 >>> import unohelper
 >>> import com.sun.star.ui
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File "uno.py", line 263, in _uno_import
     return _g_delegatee( name, *optargs, **kwargs )
ImportError: No module named com.sun.star.ui
 >>> from com.sun.star.ui import XToolPanel

So import uno and unohelper and one can import objects from the 
non-existent com.sun.star.ui module. Still, a lot more is needed to 
understand even the example.

-- 
Terry Jan Reedy






More information about the Python-list mailing list