OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Please Help - Python UNO Problem

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
LinuksGuru
General User
General User


Joined: 01 Sep 2011
Posts: 5

PostPosted: Wed Sep 28, 2011 1:51 pm    Post subject: Please Help - Python UNO Problem Reply with quote

Hi !


I have problem with Python and Uno which I cannot solve at the moment. I wrote a test function in Python which obtains and changes cell content in Calc spreadsheet.
Right it is possible to obtain cell content from Python, but it is not possible to change it.

Please look at the code below.

--------------------------------------------------

Code:
import numpy
import uno, unohelper

def GetCells(n):
    oDoc = XSCRIPTCONTEXT.getDocument()
    oSheet = oDoc.getSheets().getByName("Cap")
    # oSheet is valid object, otherwise Python would throw exception at lines below.     

    # Doesn't work, nothing happens.
    oSheet.getCellByPosition(0, 0).setString("Set String from Python 1")     
    oSheet.getCellRangeByName("C67").setFormula("=100 + 300")
    oSheet.getCellByPosition(3, 68).setValue(100.235)
   
    # Works !
    return oSheet.getCellRangeByName("A24").getString()


--------------------------------------------------

Anyone can explain what could be wrong?

I'm running SuSE 11.4 x64 and LibreOffice 3.4.2 (from stable SuSE repository).

Thanks in advance for any help.
Back to top
View user's profile Send private message
Villeroy
Super User
Super User


Joined: 04 Oct 2004
Posts: 10065
Location: Germany

PostPosted: Thu Sep 29, 2011 12:26 am    Post subject: Reply with quote

SuSE, Ubuntu and all the other Linux distros do an extremely lousy job trying to "integrate" OOo/LibO into their distributions. In fact there is nothing to integrate. SImply download and install the vanilla packages from the project site openoffice.org or libreoffice.org respectively. Since OOo 2.0.3 I block any distributor's OOo/LibO and everything works just fine.

This is the exact snippet I pasted into a python module and ran in LibO 3.4.3 under Ubuntu. This kind of simple stuff used to work since OOo 1.1.3
Code:
import uno, unohelper

def GetCells():
    oDoc = XSCRIPTCONTEXT.getDocument()
    oSheet = oDoc.getSheets().getByIndex(0)
    # oSheet is valid object, otherwise Python would throw exception at lines below.     

    # Doesn't work, nothing happens.
    oSheet.getCellByPosition(0, 0).setString("Set String from Python 1")     
    oSheet.getCellRangeByName("C67").setFormula("=100 + 300")
    oSheet.getCellByPosition(3, 68).setValue(100.235)
   
    # Works !
    return oSheet.getCellRangeByName("A24").getString()

g_exportedScripts=GetCells,

_________________
Rest in peace, oooforum.org
Get help on http://forum.openoffice.org
Back to top
View user's profile Send private message
LinuksGuru
General User
General User


Joined: 01 Sep 2011
Posts: 5

PostPosted: Thu Sep 29, 2011 2:02 am    Post subject: Reply with quote

The reason I'm use SuSE distribution of LibreOffice is quite simple - Python. Standard LibreOffice comes with built-in Python, yet "SuSE integrated" use Python from SuSE.

The application I'm writing is quite complex, and it requires numeric & scientific libraries like numpy and scipy.

With "standard" LibreOffice and its "built-in" Python interpreter it would be a problem.

Please correct me if I'm wrong.
Back to top
View user's profile Send private message
Villeroy
Super User
Super User


Joined: 04 Oct 2004
Posts: 10065
Location: Germany

PostPosted: Thu Sep 29, 2011 2:16 am    Post subject: Reply with quote

Anyhow, this is a SuSE question. They messed it up again.
_________________
Rest in peace, oooforum.org
Get help on http://forum.openoffice.org
Back to top
View user's profile Send private message
LinuksGuru
General User
General User


Joined: 01 Sep 2011
Posts: 5

PostPosted: Thu Sep 29, 2011 11:55 pm    Post subject: Reply with quote

Villeroy, what happened with the forum on OpenOffice.org? It seems to be down for several days.
Back to top
View user's profile Send private message
LinuksGuru
General User
General User


Joined: 01 Sep 2011
Posts: 5

PostPosted: Fri Sep 30, 2011 12:27 am    Post subject: Reply with quote

Villeroy, once you have posted a link on OpenOffice.org forum to sample code which pass array between LibO Basic and Python. Since OpenOffice.org forum is down, and Google cache for whatever reason don't display a copy, can you please post this link or sample here?

Thanks in advance.
Back to top
View user's profile Send private message
Villeroy
Super User
Super User


Joined: 04 Oct 2004
Posts: 10065
Location: Germany

PostPosted: Fri Sep 30, 2011 1:50 am    Post subject: Reply with quote

http://www.oooforum.org/forum/viewtopic.phtml?t=59534&highlight=basic+python
EDIT: These wrappers are very clumsy work-around for throw-away functions.
A Calc add-in with cell functions may be easier to implement for a huge collection of functions and certainly it would be easier to use and to distribute.
_________________
Rest in peace, oooforum.org
Get help on http://forum.openoffice.org
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group