I have the same code, written using win32com and xlrd. xlrd preforms the algorithm in less than a second, while win32com takes minutes.
Here is the win32com:
def makeDict(ws):
"""makes dict with key as header name,
value as tuple of column begin and column end (inclusive)"""
wsHeaders = {} # key is header name, value is column begin and end inclusive
for cnum in xrange(9, find_last_col(ws)):
if ws.Cells(7, cnum).Value:
wsHeaders[str(ws.Cells(7, cnum).Value)] = (cnum, find_last_col(ws))
for cend in xrange(cnum + 1, find_last_col(ws)): #finds end column
if ws.Cells(7, cend).Value:
wsHeaders[str(ws.Cells(7, cnum).Value)] = (cnum, cend - 1)
break
return wsHeaders
And the xlrd
def makeDict(ws):
"""makes dict with key as header name,
value as tuple of column begin and column end (inclusive)"""
wsHeaders = {} # key is header name, value is column begin and end inclusive
for cnum in xrange(8, ws.ncols):
if ws.cell_value(6, cnum):
wsHeaders[str(ws.cell_value(6, cnum))] = (cnum, ws.ncols)
for cend in xrange(cnum + 1, ws.ncols):#finds end column
if ws.cell_value(6, cend):
wsHeaders[str(ws.cell_value(6, cnum))] = (cnum, cend - 1)
break
return wsHeaders