views:

548

answers:

7

Today I needed to parse some data out from an xlsx file (Office open XML Spreadsheet). I could have just opened the files in openoffice and exported to csv. However I will need to reimport data from this spreadsheet later, and I wanted to eliminate the manual operation.

I searched on the net for xlsx parser, and all I found was a stackoverflow question asking the same thing: http://stackoverflow.com/questions/173246/parsing-and-generating-microsoft-office-2007-files-docx-xlsx-pptx

So I rolled my own.

It's 134 lines of code for the parsing and accessing off a spreadsheet, and 54 lines of code of unit tests. This of course is only tested on the 1 file I needed it, and aside from how it's used in the unit tests there are is no documentation as off now. It uses zipfile, minidom, re and unittest, so perfectly portable and platform independent.

Since I don't blog, and I don't have any desire to turn this into a python library for OfficeOpen XML, I am stuck wondering where I should post this code. I have solved a problem that I am sure others will get in the future. So I want to post my code under public domain somewhere for anyone to copy and paste into their app and adjust to fix their problem.

The implementation is simple, and here is a quick overview off the features:

workbook = Workbook(filename) # open a file
for sheet in workbook: pass # iterate over the worksheets
workbook["sheetname"] # access a sheet by name, also possible to do by index from 0
sheet["A1"] # Access cell
sheet["A"] # Access column
sheet["1"] # Access row
cell.value # Cell value - only tested with ints and strings.

Thanks for all the replies. I was going to hoste it on activestate, but the page kept crashing when sending me the activation mail. So I can't activate my code to post it.

My second choice was codeproject, and I wrote up a nice article about the file. Sadly that page crashes when I try to submit my post.

So I put it on github for any to see and branch off: http://github.com/staale/python-xlsx/tree/master

I don't want to do all the work for the python project hosting, so that's out.

Accepting the git answer, as that was the only thing that worked for me. And git rocks.

Edit: Gah, lost my entire post at codeproject, and I did such a nice writeup. Screw it, I have spent more time trying to share this than it took coding it. So I am calling it done for my part as off now. Unless I decide to tweak it more later.

+5  A: 

You should post it here. There are plenty of recipes here and yours would fit in perfectly.

Stack Overflow is meant to be a wiki, where people search for questions and find answers. That being said, if you want to post it here, what you would do is open a question relevant to your answer, then respond to your own question with your answer.

ryeguy
I wasn't looking to post it on stack overflow, as I don't think that would add to this site. I will post it to activestate when their mailer unbreaks and sends me the activation mail so I can actually log in.
Staale
+1  A: 

err, with a more descriptive title, i am sure many people would have found it here itself.(but i wasn't aware of the not-a-question tag).

Hence, you can get a free blog, and just put in the bits you want to share, that way you would also have a steady online reference whenever you need it.

Sujoy
I was using an example, but wanted a general answer. I remember being in the same situation before, so I thought the SO community would hold some good answers for me.
Staale
-1: This is not a blog, nor a stand-in for a blog, nor anything like a blog. There are numerous free blogs -- use one of those as a blog. A simple code posting gets closed as "Not A Real Question."
S.Lott
well, i actually did mention about getting a free blog!
Sujoy
@Sujoy: you sort of mentioned it. You also said "people would have found it here", which is what I objected to. You might want to edit your answer to change your emphasis.
S.Lott
A: 

It seems to me that Python Package Index is the right place for you

bgbg
+5  A: 

GitHub would also be a great place to post this. Especially as that would allow others to quickly fork their own copies and make any improvements or modifications they need. These changes would then also be available to anyone else who wants them.

Sebastian Celis
You think this guy's going to learn GIT just to post 154 lines of source code? Ha!
joeforker
I already use git daily :)
Staale
I use git too, and I love how easy it is... to corrupt my working copy! BURN!
joeforker
+2  A: 

If your code is short enough to copy and paste, you might want to post it as a Python recipe. That site is a great resource for learning Python techniques and its best contents have been compiled into a book.

If your code is reusable as-is then you should post your Python code in the Python Package Index (pypi). Organize your source code, read this tutorial on how to write a setup.py for your package. Once you have your free pypi account and have written setup.py, run python setup.py register to claim your package's name and post its metadata to the index. setup.py can also upload your package's source or binaries to pypi, for example python setup.py sdist upload would build and upload the source distribution.

Once your package is a part of the Python Package Index, other Python programmers can download and install it automatically with a number of tools including easy_install your_package.

joeforker
I don't want to maintain a project. And I think the small code snippet is more useful to just copy and paste where needed until someone makes something more serious.
Staale
+1  A: 

In general, CodeProject is a great place to post code as long as you're willing to write a small article about the code. (One of the good things about CodeProject is that they do require some verbiage about the code.) The site gets an extraordinary amount of traffic, so anything you post there will be seen.

John D. Cook
A: 

May I humbly suggest my site; http://utilitymill.com. It lets you not only post your Python code, but also makes it into a runnable web utility.

Users can collaberate on the code and write-ups, and it even gives you an automatic RESTful API for the utility for free.

Greg