Created
October 21, 2010 18:59
-
-
Save mdellavo/639082 to your computer and use it in GitHub Desktop.
XLS to Dict Reader using xlrd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
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
Thanks