0
from  xlrd import open_workbook
book = open_workbook('Workbook2.xlsx')
sheet = book.sheet_by_index(0)
keys = [sheet.cell(0,col_index).value for col_index in xrange(sheet.ncols)]
dict_list =[]
print keys
for row_index in xrange(1,sheet.nrows):
   d={keys[col_index]: sheet.cell(row_index, col_index).value for col_index in    xrange(sheet.ncols)}
   print d
   dict_list.append(d)

print dict_list

The output is not in order as the excel file. Does anyone have a better idea?

WillWill
  • 35
  • 1
  • 6
  • Possible duplicate of [Why is the order in Python dictionaries and sets arbitrary?](http://stackoverflow.com/questions/15479928/why-is-the-order-in-python-dictionaries-and-sets-arbitrary) – Alex Taylor Jun 04 '16 at 06:09

1 Answers1

0

I recommend to xlrd for reading .xls files.

but the best way is to convert this file in csv and then read in python.

NIKHIL RANE
  • 4,012
  • 2
  • 22
  • 45
  • The problem is I need to store these values in a dict and use them later. Since the order is so different than the excel file, it makes harder to use. – WillWill Jun 04 '16 at 16:33
  • trying to use dict and for loop to bulk post data (API) – WillWill Jun 05 '16 at 17:09