Locked lesson.
About this lesson
In this lesson, we'll discuss how to change the border style and thickness of a spreadsheet cell.
Exercise files
Download this lesson’s related exercise files.
28 - Borders and Sides.docx57.3 KB 28 - Borders and Sides SOLUTION.docx
55.9 KB
Quick reference
Borders and Sides
Changing Borders is often important in a spreadsheet.
When to use
Use this whenever you want to change the border style and thickness of a spreadsheet cell.
Instructions
# Import libraries
from openpyxl.styles import Side, Border
# pick a cell
cell = ws['B27]
# Define the Side and Thickness
bd = Side(style="thick", color='000000')
# Change Border
cell.border = Border(
left = bd,
right = bd,
top = bd,
bottom = bd
)
Style options include:
hair, dashDotDot, mediumDashDot, medium,
thick, dashDot, slantDashDot, double, mediumDashed,
dashed, mediumDashDotDot, thin, dotted
Hints & tips
- from openpyxl.styles import Side, Border
- bd = Side(style="thick", color='000000')
- cell.border = Border(left = bd, right = bd, top = bd, bottom = bd)
Lesson notes are only available for subscribers.