Skip to content

Instantly share code, notes, and snippets.

@wilig
Created October 8, 2010 00:25
Show Gist options
  • Save wilig/616161 to your computer and use it in GitHub Desktop.
Save wilig/616161 to your computer and use it in GitHub Desktop.
def tuplify(ws):
out = dict()
for r in range(0, ws.get_highest_row()):
for c in range(0, ws.get_highest_column()):
# openpyxl uses 1,1 as origin we expect 0,0
out[(r,c)] = ws.cell(row=r+1, column=c+1).value
return out
def check_if_xlxs(filename):
from openpyxl.reader.excel import load_workbook
try:
wb = load_workbook(filename)
return wb
except:
raise UserWarning, "Not a .xlxs file"
def parse_xlsx(stream):
wb = check_if_xlxs(stream)
return tuplify(wb.worksheets[0])
#
# stub to kick stuff off
#
filename = 'assets.xlsx'
try:
map = parse_xlsx(filename)
print map
except UserWarning:
print 'File was not a .xlsx file'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment