Python Addon in Gnumeric

Updates:

The Code has undergone significant revisions and will now always be hosted here:

https://sourceforge.net/projects/pyworkbooks/files/

I recommend you view the documentation included there.

 

 

So I've been desperately looking for a way to use python in spreadsheets, with little luck.  I found the xlrt and xlwt modules that interface with excel, but the idea of doing extensive work to make python work with excel made me sick to my stomach.  I took a long look at open office before I decided it was not for me.  Finally, I looked at the python spreadsheet pyspread.  While this looked interesting, it was still pre-Beta.

Then I stumbled onto Gnumeric.  The tutorial for the python module left an open hole in he number of things that would be difficult to do.  Use this tutorial if you are having trouble installing gnumeric or the modules, but read this blog for everything else :D 

Although the original module allowed you to do a special process to create python functions... how do you actually use them?  How do I extract data?  These questions caused me to create Pygnumeric

Pygnumeric itself interfaces with Gnumeric via the standard method (see the tutorial for details).  This method is clunky (although MUCH more effective than any other spreadsheet I had seen), and reminded me of writing C code (*shiver*).  In order to make writing python more like writing python, I set out to create a few simple functions which can be called from any cell in the worksheet.  The two you should know about now are:

py_import_function(module, function)
allows you to import a function from a named module (and assign a key-binding if you give it a third argument) that you can call with...

py_run( "function", CellRange)
py_run will call the function that you pass in as a string, plus pass an array (or value) to that function.  The array is obtained by converting a range of cells into the array.

Hopefully anyone can see the value of these.  They allow you to create your own functions that can be run inside of any Gnumeric cell.  They can be copy-pasted, have relative indexes -- they have all the benefits of a built in function and they are extremely easy to call.  Attached is the module and all the needed linker files plus a README that tells you what to do.   Also, take a look at the gnumeric file to get a small tutorial on how to do things.

For the future...
I'm looking for ways of interfacing directly with the sheet so that cell macros and outside macros can be created, but there doesn't seem to be any way for python to get the required information (although it CAN directly access sheets and change cells, there is no way to send it that information... hopefully this is fixed soon).  I would like to be able to export the sheet object so that it can be played with from external python interpreters.  I'm thinking of doing this by "registering" the sheet on a virtual server.