title: Apply Border To Range Of Cells Using Openpyxl
body: <p>I am using python 2.7.10 and openpyxl 2.3.2 and I am a Python newbie.</p>
  
  <p>I am attempting to apply a border to a specified range of cells in an Excel worksheet (e.g. <code>C3:H10</code>). My attempt below is failing with the the following message:  </p>
  
  <blockquote>
    <p>AttributeError: 'Cell' object has no attribute 'styles'. </p>
  </blockquote>
  
  <p>How do I attach a border to a cell? Any insights would be gratefully received.</p>
  
  <p>My current code:</p>
  
  <pre><code>import openpyxl
  from openpyxl.styles import Border, Side
  
  def set_border(ws, cell_range):
      rows = ws.iter_rows(cell_range)
      for row in rows:
          row[0].styles.borders = Border(left=Side(border_style='thin', color="FF000000"))
          row[-1].styles.borders = Border(right=Side(border_style='thin', color="FF000000"))
      for c in rows[0]:
          c.styles.borders = Border(top=Side(border_style='thin', color="FF000000"))
      for c in rows[-1]:
          c.styles.borders = Border(bottom=Side(border_style='thin', color="FF000000"))
  
  
  # Example call to set_border
  wb = openpyxl.load_workbook('example.xlsx')
  ws = wb.get_sheet_by_name('Sheet1')
  
  set_border(ws, "B3:H10")
  </code></pre>