Ask Your Question

Writing User Defined Functions in Python [closed]

asked 2013-01-21 21:38:01 +0100

OrionWorld gravatar image

updated 2015-10-21 04:13:27 +0100

Alex Kemp gravatar image

I stored the following simple Python script in /usr/lib/libreoffice/share/Scripts/python/pythonSamples :

import uno
def newsum(a, b):
...return a + b

What should I do to make this work as a user-defined-function in Libre Office so calling =newsum(5, 7) would simply return 12?
I have been struggling with this for a while, so any help is highly appreciated!

Note: My configuration is: Libre Office 3.6 on Ubuntu 12.10; Python plug-in has been loaded correctly [Tools --> Macros --> Organize Macros --> Python works fine].

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2015-10-21 04:13:46.765941

2 Answers

Sort by » oldest newest most voted

answered 2013-01-22 02:25:36 +0100

qubit gravatar image

Hi @OrionWorld,

It looks like there's some information about user-defined-functions in this document:

This example sounds very relevant:


Adds a function named tokencount to calc, which counts the number of words within a calc cell. After adding the extension, the office must be restarted (including terminating the quickstarter) to make the function appear in the function list.

edit flag offensive delete link more

answered 2013-02-02 22:49:41 +0100

OrionWorld gravatar image

@ qubit, thanks for your answer. For some reason I feel there should be some simple way to call a python script from basic macro. Would be interesting to work out a simple instruction to the newsum(a,b) function in LO calc.

edit flag offensive delete link more


@OrionWorld -- I'm not sure of a simple way to call a python script from a BASIC macro, but it sounds like a good feature to me.

Please feel free to file an enhancement bug and provide a description of how you'd like the config/registration of the Python scripts to work. Don't forget to mark your bug as an 'enhancement'.

Please post a link to any bugs you file in a comment below using the format "fdo#123456".

qubit gravatar imagequbit ( 2013-03-10 06:48:12 +0100 )edit

This should be a comment, not an answer

endolith gravatar imageendolith ( 2018-09-19 15:31:47 +0100 )edit

Question Tools

1 follower


Asked: 2013-01-21 21:38:01 +0100

Seen: 7,083 times

Last updated: Feb 02 '13