Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
openpyxl (2.4.8) sheet-to-dict like the csv DictReader - based on https://gist.github.com/mdellavo/853413
from openpyxl import load_workbook
def XLSXDictReader(f):
book = load_workbook(f)
sheet = book.active
rows = sheet.max_row
cols = sheet.max_column
headers = dict((i, sheet.cell(row=1, column=i).value) for i in range(1, cols))
def item(i, j):
return (sheet.cell(row=1, column=j).value, sheet.cell(row=i, column=j).value)
return (dict(item(i, j) for j in range(1, cols + 1)) for i in range(2, rows + 1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.