Search code examples
pythonlibreoffice-calccustom-function

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 ?


Solution

  • 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:

    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.