def setuplog():
from logging import handlers
socketHandler = handlers.SocketHandler('localhost',
handlers.DEFAULT_TCP_LOGGING_PORT)
rootLog = logging.getLogger('')
rootLog.addHandler(socketHandler)
The code has undergone revisions and will now always be hosted here:
https://sourceforge.net/projects/pyworkbooks/files/
Most of this tutorial is still valid, but I recommend you view the pdf file included above.
So I said I wouldn't make a lot of updates, but here is another big update. I've added several features to the code. The previous tutorial still applies, except that when you type
>>> print B[:10, 1] you will get a different value out. The best way to teach is to show, so I will do an interactive interpreterThe 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.
Note: This is my third tutorial piece on Gnumeric. See the first two here and here
import sys; sys.path.append("/home/garrett/.gnumeric/1.10.8/plugins/Pygnumeric/"); import Pygnumeric; import Gnumeric; gBook = Pygnumeric.GnWorkbook(Gnumeric); B = gBook
This will let you follow along in the interactive interpreter (do this in a new workbook, one where you can't destroy any important data :D)
Here is my interactive interpreter session, with me playing with some stuff
What you can do
- Right now the biggest things I need is bug reports and publicity. If you like the program, I strongly encourage you to do things like post on yahoo answers/reddit/your message boards/facebook/twitter/tell the people at work/tell your freinds/tell your girlfriend (only if she uses spreadsheets and likes to code python though. If she does both of these things, feel free to also send me her number). This code is free to use and free to steal, so my only tangible benefits from my efforts are becomming a better programmer and the joy of having people benefit from my blood sweat and tears (no seriously, it was really fun to make and I enjoyed it)
Anyway, MY girlfriend is here for the week, so don't expect too many updates this week!
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 there is a post I made not too long ago about the python addon for Gnumeric. All the information there is still valid, but the program just got a WHOLE LOT better
I don't have a ton of time to give a long example now, but there is a tutorial included with the file. Basically it allows for COMPLETE (and I mean complete) control of your entire workbook through python, even through the built-in interpreter if you run a few commands. There are only three things you need to know to edit any cell in your spreadsheet If you follow the macro, you can have an object called gBook. This is the object that represents your worksheet.gBook.change_sheet(sheetobject) can be passed an integer, a string, or a cell -- it will change your currently active sheet to that cell. So if you have a sheet called "sandbox" and you say gBook.change_sheet("sandbox") then you can start editing the sheet sandbox! gBook.change_range( tuple or cell_range) will change the reference cell. For playing around you should just set it to (0,0) -- like thisgBook.change_range( (0,0) )now lets say you wanted to read the first 10 columns in the first row. Just type: data = gBook[0, :9]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 :DAlthough 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)