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
  dataframe cell conditional format by row SriRajesh 0 566 Apr-24-2021, 11:51 AM
Last Post: SriRajesh
Smile Set 'Time' format cell when writing data to excel and not 'custom' limors 3 1,162 Mar-29-2021, 09:36 PM
Last Post: Larz60+
  How to append a value to specific excel cell using openpyxl hobbyist 0 1,321 Mar-05-2021, 07:14 PM
Last Post: hobbyist
  P3, openpyxl, csv to xlsx, cell is not number, problem with colorize genderbee 1 609 Sep-29-2020, 03:20 PM
Last Post: Larz60+
  regular expressions in openpyxl. format picnic 0 786 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 6,680 Oct-12-2019, 10:57 PM
Last Post: curranjohn46
  Openpyxl, format color of cells (cols) based on condition. genderbee 0 4,895 Sep-11-2019, 01:05 PM
Last Post: genderbee
  Change Time Format in Python bluethundr 2 1,156 Mar-04-2019, 09:13 PM
Last Post: bluethundr
  Change format of datetime Jonas85 6 1,772 Feb-05-2019, 03:47 PM
Last Post: Jonas85
  OpenPyxl Cell.value Alignment pcsailor 0 6,671 Sep-10-2018, 01:09 AM
Last Post: pcsailor

Forum Jump:

User Panel Messages

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