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
  P3, openpyxl, csv to xlsx, cell is not number, problem with colorize genderbee 1 150 Sep-29-2020, 03:20 PM
Last Post: Larz60+
  regular expressions in openpyxl. format picnic 0 349 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 3,963 Oct-12-2019, 10:57 PM
Last Post: curranjohn46
  Openpyxl, format color of cells (cols) based on condition. genderbee 0 2,749 Sep-11-2019, 01:05 PM
Last Post: genderbee
  Change Time Format in Python bluethundr 2 652 Mar-04-2019, 09:13 PM
Last Post: bluethundr
  Change format of datetime Jonas85 6 1,085 Feb-05-2019, 03:47 PM
Last Post: Jonas85
  OpenPyxl Cell.value Alignment pcsailor 0 3,427 Sep-10-2018, 01:09 AM
Last Post: pcsailor
  Best way to set cell background colour in openpyxl Pedroski55 4 43,461 Aug-08-2018, 01:24 PM
Last Post: sumandas89
  using openpyxl copy the value of a cell, not the formula Pedroski55 3 18,497 Jan-07-2018, 11:44 PM
Last Post: Pedroski55
  Reading and writing to text file has format change cheerful 3 1,531 Dec-21-2017, 07:53 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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