Skip to content

Instantly share code, notes, and snippets.

@LegoStormtroopr
Created February 20, 2013 10:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LegoStormtroopr/4994491 to your computer and use it in GitHub Desktop.
Save LegoStormtroopr/4994491 to your computer and use it in GitHub Desktop.
A demonstration of how to read Excel files using xlrd - http://www.lexicon.net/sjmachin/xlrd.htm
Using: http://www.abs.gov.au/ausstats/meisubs.NSF/log?openagent&634501.xls&6345.0&Time%20Series%20Spreadsheet&D22A58332C098EE7CA257B17000D3976&0&Dec%202012&20.02.2013&Latest
>>> data = abs.xlrdDemo('634501 (1).xls')
>>> print data.keys()
[u'Index', u'Data1', u'Inquiries']
>>> print data['Data1'][10,5]
64.7
>>> print data['Inquiries']
{(9, 1): u'I N Q U I R I E S', (3, 0): '', (8, 0): '', (2, 1): '', (5, 1): u'Table 1. Total Hourly Rates of Pay Excluding Bonuses: Sector, Original, Seasonally Adjusted and Trend', (4, 0): '', (9, 0): '', (8, 1): '', (11, 1): u'Referral Service on 1300 135 070 or Luci Burrage on Perth (08) 9360 5151.', (5, 0): '', (10, 0): '', (4, 1): u'6345.0 Wage Price Index, Australia', (1, 1): u'Time Series Workbook', (0, 0): '', (7, 1): '', (6, 0): '', (11, 0): '', (10, 1): u'For further information about these and related statistics, contact the National Information and', (1, 0): '', (0, 1): '', (7, 0): '', (6, 1): '', (3, 1): '', (2, 0): ''}
def xlrdDemo(myExcelFile):
book = xlrd.open_workbook(myExcelFile)
data = {}
for sh in book.sheets():
data[sh.name] = {}
for row in range(0,sh.nrows):
for col in range(0,sh.ncols):
c = sh.cell(row,col)
val = c.value
if c.ctype == xlrd.XL_CELL_DATE:
val = datetime(* xlrd.xldate_as_tuple(c.value,book.datemode))
data[sh.name][row,col] = val
return data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment