Python Forum

Full Version: openpyxl, if value in cell then change format
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,
my code is not working and I don't know why.
I need change font size when value in cell is '2', for A1 to A100.

# load libs
from openpyxl import load_workbook
from openpyxl.styles import colors
from openpyxl.styles import Font, Color

# load xlsx
wb = load_workbook('uh201910.xlsx')
ws = wb.active

# for A1 to A100, if Ax is 2 then change font size to 124 for Ax
cells = ws['A1':'A100']
for i in cells:
    if i == 2:
        ws['i'] = Font(size=124)

# saving
wb.save('styles.xlsx')
Thank you.