Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6624773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:41:39+00:00 2026-05-25T21:41:39+00:00

To extend OpenOffice’s capabilities, I’ve defined some Python macros in a file in the

  • 0

To extend OpenOffice’s capabilities, I’ve defined some Python macros in a file in the user script directory (~/Library/Application Support/OpenOffice.org/3/user/Scripts/python/, in my case). The macros are visible in the Python macro organizer. However, using the functions in a cell formula results in “#NAME?” (OO.org error 525).

Suppose I’ve defined the following function :

def pytype(val):
    return str(type(val))

How can I call pytype in a cell formula (e.g. =PYTYPE("string"))?

Background

I’m importing some data from Authorize.net into a MySQL database for analysis. MySQL can’t parse the date & time format used by Authorize.net into a DATETIME or TIMESTAMP field, so I’m trying to massage the data into a format MySQL can handle before import. OpenOffice also doesn’t recognize the data as a date & time and, as far as I’ve been able to determine, OO.Org doesn’t have a generic date parsing function. Thus I’m extending OO.org’s capabilities.

There are other approaches to the larger issue. For example, I could also try to fix up the data in MySQL post-import using additional columns. In fact, this is what I did the first time; however, there’s now existing data in the table to contend with. Because of that, and because there are other tasks in the future I hope to accomplish by using macros in formulas, for now I’m mostly interested in calling Python macros in formulae.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T21:41:39+00:00Added an answer on May 25, 2026 at 9:41 pm

    On the old OO.org forums, (super)user Villeroy posted an illustration of how to call Python functions from OO.org Basic, which can then be used in formulae. The key is to use the com.sun.star.script.provider.MasterScriptProviderFactory service as a bridge. Here is an adaptation of his solution, generalized to call arbitrary functions in arbitrary modules:

    REM Keep a global reference to the ScriptProvider, since this stuff may be called many times: 
    Global g_MasterScriptProvider as Object
    REM Specify location of Python script, providing cell functions: 
    Const URL_Main as String = "vnd.sun.star.script:" 
    Const URL_Args as String = "?language=Python&location=user" 
    
    Function invokePyFunc(file AS String, func As String, args As Array, outIdxs As Array, outArgs As Array)
       sURL = URL_Main & file & ".py$" & func & URL_Args
       oMSP = getMasterScriptProvider()
       On Local Error GoTo ErrorHandler
          oScript = oMSP.getScript(sURL)
          invokePyFunc = oScript.invoke(args, outIdxs, outArgs)
          Exit Function
       ErrorHandler:
          Dim msg As String, toFix As String
          msg = Error$
          toFix = ""
          If 1 = Err AND InStr(Error$, "an error occurred during file opening") Then
             msg = "Couldn' open the script file."
             toFix = "Make sure the 'python' folder exists in the user's Scripts folder, and that the former contains " & file & ".py."
          End If
          MsgBox msg & chr(13) & toFix, 16, "Error " & Err & " calling " & func
    end Function
    
    Function getMasterScriptProvider() 
       if isNull(g_MasterScriptProvider) then 
          oMasterScriptProviderFactory = createUnoService("com.sun.star.script.provider.MasterScriptProviderFactory") 
          g_MasterScriptProvider = oMasterScriptProviderFactory.createScriptProvider("") 
       endif 
       getMasterScriptProvider = g_MasterScriptProvider
    End Function
    

    This can then be used to create a OO.org Basic function callable in a formula. Using the example pytype:

    Const libfile as String = "util"    REM functions live in util.py
    
    Function pytype(value)
        pytype = invokePyFunc(libfile, "pytype", Array(value), Array(), Array())
    End Function
    

    Another potential implementation is to create a Python add-in. However, this is a much heavier option as it requires installing the OpenOffice SDK, and it isn’t obvious to me whether this approach would work for free functions or only works for classes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to extend some base classes in Python: class xlist (list): def len(self):
I want to extend a WPF application with database functionality. Which database engine would
I want to extend an existing application I made to make it set mixer
is it possible to extend vim functionality via custom extension (preferably, written in Python)?
To extend the User object with custom fields, the Django docs recommend using UserProfiles
I extend upon a legacy library which accesses files on the harddrive. I have
I'm trying to extend the functionality of an ASP.net application that I'm working with.
I'm looking to extend the GridSplitter in some way to add a button which
I want to extend a maven2 POM to run some post processing on my
Is it possible to extend the original permissions given by the user? So, once

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.