Skip to content

Instantly share code, notes, and snippets.

@mdellavo
Created October 21, 2010 18:59
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save mdellavo/639082 to your computer and use it in GitHub Desktop.
Save mdellavo/639082 to your computer and use it in GitHub Desktop.
XLS to Dict Reader using xlrd
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
@manelclos
Copy link

Thanks!

@amykochu
Copy link

Thanks

@dnk8n
Copy link

dnk8n commented Sep 28, 2021

I did similar for xlsx using openpyxl. Potentially useful if you are looking here - https://gist.github.com/dnk8n/925db332579a539f9dea37301906fd45

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment