def read_sheet1(book, sheet_index): datemode = book.datemode sh = book.sheet_by_index(sheet_index) ncolumns = sh.ncols #utility functions cleanrow_ = lambda row_: [x if x is not '' else None for x in row_] xlCellValue = lambda cell_: xlValue(cell_, datemode, 1) qdata = {} for rowx in range(sh.nrows): try: xr = map(xlCellValue, sh.row(rowx)) except: print("problem in row: %s\n%s" % (rowx, sh.row(rowx))) continue else: xrvalues = cleanrow_(xr) if xrvalues: if type(xrvalues[0]) == str: if xrvalues[0].find("Index") == 0: key = xrvalues[1].strip() qdata[key] = {} elif type(xrvalues[0]) == date: if xrvalues[1]: qdata[key][xrvalues[0]] = xrvalues[1:] else: # if there are gaps in the data, reset # because ML resets the cumm index to 100 when # it starts again. qdata[key] = {} return qdata
def read_sheet2(book, sheet_index, hdr_): datemode = book.datemode sh = book.sheet_by_index(sheet_index) ncolumns = sh.ncols #utility functions cleanrow_ = lambda row_: [x if x is not '' else None for x in row_] xlCellValue = lambda cell_: xlValue(cell_, datemode, 1) irow = map(xlCellValue, sh.row(0)) idx = [n for n in range(len(irow)) if irow[n].find("Index") ==0] hdata = [(n, irow[n+1]) for n in idx] qdata = dict( [(irow[n+1], {}) for n in idx] ) for rowx in range(2, sh.nrows): try: xr = map(xlCellValue, sh.row(rowx)) except: print("problem in row: %s\n%s" % (rowx, sh.row(rowx))) continue else: xrvalues = cleanrow_(xr) for n, key in hdata: if xrvalues[n+1]: qdata[key][xrvalues[n]] = xrvalues[n+1:n+1+len(hdr_)] else: # if there are gaps in the data, reset # because ML resets the cumm index to 100 when # it starts again. qdata[key] = {} return qdata