Skip to content

Instantly share code, notes, and snippets.

@alecklandgraf
Forked from mdellavo/xls-dict-reader.py
Created August 18, 2014 21:29
Show Gist options
  • Save alecklandgraf/038573d57b11e4791727 to your computer and use it in GitHub Desktop.
Save alecklandgraf/038573d57b11e4791727 to your computer and use it in GitHub Desktop.
try:
import xlrd
def XLSDictReader(f, sheet_index=0):
data = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
book = xlrd.open_workbook(file_contents=data)
sheet = book.sheet_by_index(sheet_index)
def item(i, j):
return (sheet.cell_value(0,j), sheet.cell_value(i,j))
return ( dict(item(i,j) for j in range(sheet.ncols)) \
for i in range(1, sheet.nrows) )
except ImportError:
XLSDictReader = None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment