title: Condition check worksheet range python
body: <p>I have a program that parses data from multiple workbook with multiple worksheets.</p>
  
  <p>sheets 2 to 9 are days of the week(Sun-Sat). However some sheets have a different sheet range. </p>
  
  <p>Some sheets have 2 to 5(Mon-Fri). Everything else is the same only some workbook have a total of 10 sheets while other have 8 sheets. My code will do the same parsing of cell range. </p>
  
  <p>How can I still use my code to parse the workbooks that have a sheet range(2, 5)? This is what I have so far. </p>
  
  <pre><code>import glob
  import openpyxl
  
  path = 'C:/SomeFolder/*.xlsx'
  files = glob.glob(path)
  for file in files:
  wb = openpyxl.load_workbook(file, data_only=True)
  NameFile = file.rsplit('~', 2)[0]
  sheet = wb.get_sheet_by_name('Title')
  sheet2 = wb.get_sheet_by_name('TOTAL')
  Week = sheet.cell(row=1, column=1).value
  Date = sheet.cell(row=2, column=1).value
  Name = sheet.cell(row=4, column=2).value
  Title = sheet.cell(row=5, column=2).value
  Site = sheet.cell(row=6, column=2).value
  LocID = sheet.cell(row=7, column=2).value
  Total = sheet2.cell(row=26, column=2).value
  if wb.worksheets is range(2, 9):
      for n in range(2, 9):
          sheets = wb.worksheets[n]
          Days = wb.sheetnames[n]
          comment = sheets.cell(row=34, column=5).value
          for i in range(2, 57):
              From = sheets.cell(row=i, column=1).value
              To = sheets.cell(row=i, column=2).value
              Activity = sheets.cell(row=i, column=3).value
              TimeSheet = {'Sender': NameFile, 'Week': Week, 'Date': Date, 'Name': Name, 'Title': Title, 'Site': Site, 'LocID': LocID,
                          'Days': Days, 'From': From, 'To': To, 'Activity': Activity, 'Week Total': Total, 'Comments': comment}
  else:
      for n in range(2, 5):
          for n in range(2, 9):
              sheets = wb.worksheets[n]
              Days = wb.sheetnames[n]
              comment = sheets.cell(row=34, column=5).value
              for i in range(2, 57):
                  From = sheets.cell(row=i, column=1).value
                  To = sheets.cell(row=i, column=2).value
                  Activity = sheets.cell(row=i, column=3).value
                  TimeSheet = {'Sender': NameFile, 'Week': Week, 'Date': Date, 'Name': Name, 'Title': Title,
                               'Site': Site, 'LocID': LocID,
                               'Days': Days, 'From': From, 'To': To, 'Activity': Activity, 'Week Total': Total,
                               'Comments': comment}
  print(TimeSheet)
  </code></pre>