Locked lesson.
About this lesson
Pattern Fill allows you to change the color and pattern of a cell.
Exercise files
Download this lesson’s related exercise files.
26 - Cell Fill (Pattern Fill).docx57.3 KB 26 - Cell Fill (Pattern Fill) SOLUTION.docx
58 KB
Quick reference
Cell Fill (Pattern Fill)
Pattern Fill allows you to change the color and pattern of a cell.
When to use
Use this whenever you want to change the color and pattern of a cell in a spreadsheet.
Instructions
# Import the PatternFill Library
from openpyxl.styles import PatternFill
# Pick a cell
cell = ws["A3"]
# Change the pattern fill
cell.fill = PatternFill(
'solid',
fgColor = 'bb9c68',
)
Your fill options are:
darkGrid, lightUp, gray125, darkVertical, lightDown, lightVertical,
lightHorizontal, mediumGray, lightGrid, darkGray, darkDown, gray0625,
lightGray, darkUp, darkHorizontal, lightTrellis, darkTrellis, solid
Hints & tips
- from openpyxl.styles import PatternFill
- cell.fill = PatternFill()
Lesson notes are only available for subscribers.