Python Forum
openpyxl, if value in cell then change format
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
openpyxl, if value in cell then change format
#1
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.
Reply
#2
https://stackoverflow.com/questions/5871...d-on-value
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Openpyxl-change value of cells in column based on value that currently occupies cells phillipaj1391 5 9,570 Mar-30-2022, 11:05 PM
Last Post: Pedroski55
  dataframe cell conditional format by row SriRajesh 0 1,724 Apr-24-2021, 11:51 AM
Last Post: SriRajesh
Smile Set 'Time' format cell when writing data to excel and not 'custom' limors 3 6,195 Mar-29-2021, 09:36 PM
Last Post: Larz60+
  How to append a value to specific excel cell using openpyxl hobbyist 0 4,761 Mar-05-2021, 07:14 PM
Last Post: hobbyist
  P3, openpyxl, csv to xlsx, cell is not number, problem with colorize genderbee 1 2,098 Sep-29-2020, 03:20 PM
Last Post: Larz60+
  regular expressions in openpyxl. format picnic 0 2,448 Mar-28-2020, 09:47 PM
Last Post: picnic
  Need to copy column of cell values from one workbook to another with openpyxl curranjohn46 3 11,080 Oct-12-2019, 10:57 PM
Last Post: curranjohn46
  Openpyxl, format color of cells (cols) based on condition. genderbee 0 8,039 Sep-11-2019, 01:05 PM
Last Post: genderbee
  Change Time Format in Python bluethundr 2 2,636 Mar-04-2019, 09:13 PM
Last Post: bluethundr
  Change format of datetime Jonas85 6 3,469 Feb-05-2019, 03:47 PM
Last Post: Jonas85

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020