Saturday, July 24, 2010

Python Library for Reading Excel Files

Came across a pretty sweet python library for reading data from Excel files: http://pypi.python.org/pypi/xlrd. Xlrd is super easy to install and use. Here's a snippet of code:
1:  import xlrd  
2:
3: mybook = xlrd.open_workbook("test.xls")
4: sheets = mybook.sheets()
5: for sheet in sheets:
6: for i in range(sheet.nrows):
7: for j in range(sheet.ncols):
8: cell = sheet.cell(i, j)
9: if cell.ctype != xlrd.XL_CELL_EMPTY:
10: print cell.value
11:

There are many other cool things you can do with xlrd. I encourage you to try it out!

No comments:

Post a Comment