def breakdownXLS(spreadsheet): ###open workbook and create dictionary of the spreadsheets within STARTCOL = 0 ENDCOL = 10 xlsbook = xlrd.open_workbook(spreadsheet) print "\n"+"-"*50 print "Checking workbook:",os.path.split(spreadsheet)[1] print "-"*50 if (xlsbook.nsheets != 0): #check if workbook has spreadsheets worksheetDic = dict() #create list of sheets in workbook sheetList = xlsbook.sheets() for sheet in sheetList: if (sheet.nrows == 0): #check if sheet has rows in it. skip if 0 continue # print "Sheet name:",sheet.name, "Rows:",sheet.nrows rowList = [] numberOfRows = sheet.nrows #get number of rows in each spread sheet counter = 0 while counter < numberOfRows: currentRow = sheet.row_slice(counter, start_colx=STARTCOL, end_colx=ENDCOL) #get row with only 10 columns rowList.append(currentRow) #add current row to rowlist counter += 1 worksheetDic[sheet.name] = rowList #put list of rows in dictionary with worksheet name as the key return worksheetDic else: print "Workbook has no spreadsheets in it." sys.exit()
def breakdownXLS(excelWorkbook): ###open workbook and create dictionary of the spreadsheets within STARTCOL = 0 ENDCOL = 10 xlsbook = xlrd.open_workbook(excelWorkbook) if (xlsbook.nsheets != 0): #check if workbook has spreadsheets worksheetDic = dict() #create list of sheets in workbook sheetList = xlsbook.sheets() for sheet in sheetList: rowList = [] numberOfRows = sheet.nrows #get number of rows in each spread sheet counter = 0 while counter < numberOfRows: currentRow = sheet.row_slice(counter, start_colx=STARTCOL, end_colx=ENDCOL) #get row with only 10 columns if (currentRow[0].value != ''): rowList.append(currentRow) #add current row to rowlist counter += 1 else: counter += 1 worksheetDic[sheet.name] = rowList #put list of rows in dictionary with worksheet name as the key return worksheetDic else: print "Workbook has no spreadsheets in it." sys.exit()