IRONSOFTWAREHOME
Excel Conditional Formatting
from ironxl import *

# Load existing spreadsheet
workbook = WorkBook.Load("sample.xlsx")
worksheet = workbook.DefaultWorkSheet

# Create conditional formatting rule
rule = worksheet.ConditionalFormatting.CreateConditionalFormattingRule(ComparisonOperator.LessThan, "8")
# Set style options
rule.FontFormatting.IsBold = True
rule.FontFormatting.FontColor = "#123456"
rule.BorderFormatting.RightBorderColor = "#ffffff"
rule.BorderFormatting.RightBorderType = BorderType.Thick
rule.PatternFormatting.BackgroundColor = "#54bdd9"
rule.PatternFormatting.FillPattern = FillPattern.Diamonds
# Apply formatting on the specified region
worksheet.ConditionalFormatting.AddConditionalFormatting("A3:A8", rule)

# Create another conditional formatting rule
rule1 = worksheet.ConditionalFormatting.CreateConditionalFormattingRule(ComparisonOperator.Between, "7", "10")
# Set style options
rule1.FontFormatting.IsItalic = True
rule1.FontFormatting.UnderlineType = FontUnderlineType.Single
# Apply formatting on the specified region
worksheet.ConditionalFormatting.AddConditionalFormatting("A3:A9", rule1)

# Save changes with applied conditional formatting
workbook.SaveAs("applyConditionalFormatting.xlsx")
pip install ironxl
Excel Conditional Formatting

Excel Conditional Formatting

IronXL for Python supports Conditional Formatting of cells and ranges. Conditional Formatting changes the style of a cell - such as background color or text formatting - based on logical or programmatic rules.

Use CreateConditionalFormattingRule(formula) to create a conditional formatting rule based on a Boolean expression. When the formula evaluates to True, the cell is highlighted. The formula provided must return a Boolean result.

The three-parameter overload of CreateConditionalFormattingRule accepts only ComparisonOperator.Between or ComparisonOperator.NotBetween as the first parameter.

Conditional formatting enables developers to highlight cells and ranges with specific color and format combinations depending on each cell's value. This makes it straightforward to analyze data, detect issues, and identify patterns and trends directly within the Excel file.

Learn to Apply Conditional Formatting in Python

Ready to Get Started?

Version:2026.9just released

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required