Created
March 17, 2014 18:22
-
-
Save robdennis/9605214 to your computer and use it in GitHub Desktop.
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
# coding=utf-8 | |
import xlrd | |
def get_header_row(sheet): | |
return sheet.row_values(sheet._first_full_rowx) | |
def yield_dict_for_sheet(sheet): | |
header = get_header_row(sheet) | |
for row_idx in xrange(sheet.nrows): | |
cells = sheet.row_values(row_idx, 0, len(header)) | |
yield { | |
col_header: cell | |
for col_header, cell in zip(header, cells) | |
} | |
def get_objects_from_book(): | |
book = xlrd.open_workbook('test_spreadsheet.xlsx') | |
data = { | |
sheet.name: list(yield_dict_for_sheet(sheet)) | |
for sheet in book.sheets() | |
} | |
import pprint | |
pprint.pprint(data) | |
if __name__ == '__main__': | |
get_objects_from_book() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment