Python plugin for Gnumeric spreadsheet

Jon K Hellan hellan at acm.org
Mon Feb 21 16:57:44 EST 2000


I am looking for suggestions.

The Gnumeric spreadsheet has a plugin which lets you define
spreadsheet functions in Python. General scripting of the spreadsheet
is not (yet?) supported.

To give you an idea, here is how a very simple function is defined in
Python and made available to Gnumeric:

import gnumeric

# Function definition
def mid(text,start_num,num_chars):
	return text[start_num-1:start_num+num_chars-1];

# Help text for Gnumeric
help_mid = \
	"@FUNCTION=MID\n" 						\
	"@SYNTAX=MID(text,start,num_chars)\n"				\
	"@DESCRIPTION="							\
	"Returns a specific number of characters from a text string, " 	\
	"starting at START and spawning NUM_CHARS.  Index is counted "  \
	"starting from one"

# register_function is a C function in Gnumeric to - you guessed it -
# register the function. The parameters are:
# - function name
# - parameter types
# - paremeter names - for use in the function wizard
# - help string
# - python function
gnumeric.register_function ("mid", "sff", "text, start_num, num_chars",
			    help_mid, mid);

The plugin doesn't yet handle booleans properly. Python is happy to
consider 0 or None false, and everything else true. But inside
Gnumeric, booleans are a distinct datatype. A function defined in
Python may receive a boolean from a C function, and will want to
return it to the spreadsheet without converting to integer. So a
distinguished boolean datatype is needed.

What is the most pythonesque way to do that?

I forgot to mention. Gnumeric tries to be compatible with Excel.

Who can help?

Jon



More information about the Python-list mailing list