Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Define a LibreOffice Calc custom function in Python

I am writing custom functions in LibreOffice Calc. Such functions must be called in Calc as if they were native functions,

e.g. as EDATE(), DAYS() etc.

Upto now what I am doing for each custom function is:

  1. Define a Python function
  2. Define a StarBasic function which invokes its Python correspondant
  3. Call StarBasic function from Calc.

It works, but it is quite impractical to write each function in two languages.

My question is: is it possible to write such kind of functions directly in Python ? Do you have any reference to share ?

like image 455
Nicola Mingotti Avatar asked Oct 21 '25 02:10

Nicola Mingotti


1 Answers

A Calc add-in is a complete solution, with features such as tooltip popups that Basic user-defined functions cannot provide.

This requires more effort than writing a Basic-Python bridge call. However, since you are writing many functions, it might not be too much extra work, because all of them can be put into a single .oxt file.

An example of the required files is in my answer at https://ask.libreoffice.org/en/question/133794/how-to-use-develop-addins-in-calc/?answer=133870#post-id-133870.

Other examples and documentation:

  • https://forum.openoffice.org/en/forum/viewtopic.php?f=20&t=83856
  • https://ask.libreoffice.org/en/question/10219/writing-user-defined-functions-in-python/
  • How can I call a Python macro in a cell formula in OpenOffice.Org Calc?

If you try it and need help, edit the question. Or post something on ask.libreoffice.org, which allows attachments as long as you have at least a small amount of reputation.

like image 88
Jim K Avatar answered Oct 23 '25 15:10

Jim K