Python plugin for Gnumeric spreadsheet

Harry G. George hgg9140 at skewer.ca.boeing.com
Wed Feb 23 12:40:11 EST 2000


Not necessarily the best way, but possible:

class Bool:
	def __init__(self,cbool):
		self.cbool=cbool
		#determine value from analyzing cbool
		self.value=(cbool=='T') 
	def __call__(self):
		return self.value

def test():
	#---load the data---
	p=Bool('T')
	q=Bool('F')
	r=Bool('T')
	s=Bool('F')

	#---use it---
	if p() and not q() and r() and not s():
		print "test ok"
	else:
		print "test fails"

	#---report it back out---
	send_to_gnumeric(r.cbool)
	...
 

Jon K Hellan <hellan at acm.org> writes:

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

-- 
Harry George                E-mail:  harry.g.george at boeing.com 
The Boeing Company          Renton:  (425) 237-6915 
P. O. Box 3707  OY-89       Everett: (425) 266-3149 
Seattle, WA 98124-2207      Page:    (425) 631-8803




More information about the Python-list mailing list