Locked lesson.
About this lesson
We can easily change the gradient color of a cell in a spreadsheet.
Exercise files
Download this lesson’s related exercise files.
27 - Cell Fill (Gradient Fill).docx57.2 KB 27 - Cell Fill (Gradient Fill) SOLUTION.docx
56 KB
Quick reference
Cell Fill (Gradient Fill)
We can easily change the gradient color of a cell in a spreadsheet.
When to use
Use this whenever you want to add a gradient style to a spreadsheet cell.
Instructions
# Import the GradientFill library
from openpyxl.styles import GradientFill
# Pick a cell to change:
cell = ws['E15']
# Change the Gradient:
cell.fill = GradientFill(
stop = ("startcolor", "stopcolor"),
)
Note: "startcolor" and "stopcolor" in the code above should be replaced with hex color codes, e.g. 000000 and ffffff for black and white.
Hints & tips
- from openpyxl.styles import GradientFill
- cell.fill = GradientFill(stop = ("startcolor", "stopcolor"),)
Lesson notes are only available for subscribers.