wrote this to get a list of dict with a key/value pair with key as col
name and value as its corresponding row value...
i'l b glad if its an aid to a programmer.
import xlrd
def get_xls_info_list( sheet_name, sheet_no ):
'''
Function: takes as arguments excel sheet name, sheet number within
excel
Returns: a list of dictionaries.
Each dict: key:: column name, value:: row value corresponding to
current column(key)
'''
wb = xlrd.open_workbook(sheet_name)
sh = wb.sheet_by_index(sheet_no)
rowlist = sh.__dict__['_cell_values']
colname_list = rowlist[0]
rowval_list = rowlist[1:]
value_dict_list = []
for each_rowval_index, each_rowval_list in enumerate(rowval_list):
val_dict = {}
for val_index, val in enumerate(each_rowval_list):
val_dict[colname_list[val_index]] = val
value_dict_list.append(val_dict)
return value_dict_list
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.