Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
15. Summary


Well done! Let's summarize what we've learned in this part:

  1. We can load Excel files into Python using the load_workbook function:
    wb = load_workbook("workbook_name.xlsx")
  2. To get the names of available worksheets, we can use the sheetnames property. It returns a list of all worksheet names: wb.sheetnames
  3. We can access a particular worksheet using either the get_sheet_by_name() method or brackets:
  4. We find out which worksheet is active by checking the active property:
  5. We can access a particular cell in two ways:
    • By using the cell property and specifying the row and column parameters:
      selected_ws.cell(row=1, column=1)
    • By using the A1 notation inside brackets:
  6. Each cell can provide us with a lot of data:
    selected_cell = ws.cell(row=1, column=1)
    selected_cell.value # the value held in a given cell
    selected_cell.coordinate # the position of a cell in A1 notation
    selected_cell.row # the row position of a cell
    selected_cell.column # the column position of a cell
  7. We can iterate over the rectangular area of a given worksheet using bracket notation:
    for row in worksheet["A1":"D4"]:
      for cell in row:
  8. We can also use the iter_rows() method:
    for row in worksheet.iter_rows(max_col=..., max_row=...):
      for cell in row:

Okay, time for a quick review!


Click Next exercise to continue.