How to Change the color of certain words in a cell

Viewed 34

for example: The quick brown fox jumps over a lazy dog.

enter image description here

1 Answers

you can use Font class:

from openpyxl.styles import Font
from openpyxl import Workbook
wb = Workbook()
filename = "hello_world.xlsx"

ws = wb.active
a1 = ws['A1']
a2 = ws['A2']
b1 = ws['B1']
b2 = ws['B2']

a1.value = 'red'
a2.value = 'green'
b1.value = 'blue'
b2.value = 'yellow'
a1.font = Font(color="FF0000")
a2.font = Font(color='00FF00')
b1.font = Font(color='0E34EB')
b2.font = Font(color='F4F215')
wb.save(filename=filename)
Related