Mastering Conditional
Formatting in Excel Using
Python: A Comprehensive
Guide
Conditional formatting is a valuable feature in spreadsheet
applications like Microsoft Excel and Google Sheets. It allows you to
automatically change the appearance of cells — using colors, icons, or
data bars — based on the values they contain. This makes it easier to
analyze and understand your data by highlighting key trends, patterns,
and outliers. With conditional formatting, you can quickly see
important information at a glance, helping you make informed
decisions.
In this blog, we’ll delve into how to master conditional formatting in
Excel using Python.
Table of Contents
Set Up Your Environment
Understanding the Types of Conditional Formatting in Excel
Add Conditional Formatting to Excel in Python
Complete Code Example
Conclusion
Set Up Your Environment
Before you start working with conditional formatting in Excel, you
need to ensure that Python is installed on your computer. If you
haven’t done this yet, you can download and install Python from
the official Python website.
Once Python is installed, you’ll need to install the [Link] for
Python library, which will enable you to manipulate Excel files and
apply various conditional formatting. To install this library, follow
these steps:
Open your terminal (Command Prompt on Windows, Terminal on
macOS or Linux).
Type the following command and press Enter:
pip install [Link]
Understanding the Types of Conditional Formatting in
Excel
Conditional formatting comes in various types, each designed to
address specific data visualization needs. Below are the main types of
conditional formatting commonly available in Microsoft Excel:
Cell Value-Based: Formats cells based on their values (e.g.,
greater than, less than).
Color Scales: Applies gradient colors to create heat maps.
Data Bars: Adds horizontal bars proportional to cell values.
Icon Sets: Inserts icons (e.g., arrows, traffic lights) to represent
data trends.
Top/Bottom Rules: Highlights top or bottom values (e.g., top
10%, above average).
Duplicate/Unique Values: Highlights duplicate or unique
entries in a dataset.
Date-Based: Formats cells based on date criteria (e.g., past due,
upcoming).
Blank/Non-Blank: Highlights empty or non-empty cells.
Custom Formula-Based: Uses formulas to define complex
formatting rules.
Text-Based: Formats cells based on text content (e.g., contains,
starts with).
Row/Column-Based: Formats entire rows or columns based on a
condition in one cell.
Error or Warning Formatting: Highlights cells with errors or
invalid data.
Add Conditional Formatting to Excel in Python
The [Link] for Python library supports nearly all of the conditional
formatting types mentioned above. The examples below illustrate how
to implement several common types of conditional formatting with this
library. In the end of this article, you will find a complete code example
that includes all the conditional formatting techniques.
Example 1: Cell Value-Based Conditional Formatting
Cell value-based conditional formatting allows you to apply formatting
rules based on the numeric values in a cell. This is useful for
highlighting cells that meet specific criteria, such as values greater than
or less than a certain threshold.
from [Link] import *
# Initialize a new workbook and load an existing Excel file
workbook = Workbook()
[Link]("conditional_formatting_example.xlsx")
# Access the first worksheet in the workbook
worksheet = [Link][0]
# Create a conditional formatting rule for the range "B2:B6"
format = [Link]()
[Link]([Link]["B2:B6"])
# Define the condition for the formatting rule
condition = [Link]()
# Set the format type to cell value
[Link] = [Link]
# Set the comparison operator to 'greater than'
[Link] = [Link]
# Specify the threshold value
[Link] = "75"
# Set the background color to yellow
[Link] = [Link](204, 204, 0)
# Save the modified workbook to a new file
[Link]("[Link]", ExcelVersion.Version2016)
# Release resources associated with the workbook
[Link]()
Set Cell Value Based Conditional Formatting in Excel in Python
Example 2: Color Scales
Color scales provide a visual representation of data by applying a
gradient of colors based on the values in the cells. This is particularly
effective for identifying trends and patterns in large datasets.
from [Link] import *
# Initialize a new workbook and load an existing Excel file
workbook = Workbook()
[Link]("conditional_formatting_example.xlsx")
# Access the first worksheet in the workbook
worksheet = [Link][0]
# Create a conditional formatting rule for the range "B2:B6"
format = [Link]()
[Link]([Link]["B2:B6"])
# Define the condition for the formatting rule
condition = [Link]()
# Set the format type to color scale
[Link] = [Link]
# Save the modified workbook to a new file
[Link]("[Link]", ExcelVersion.Version2016)
# Release resources associated with the workbook
[Link]()
Set Color Scales Conditional Formatting in Excel in Python
Example 3: Data Bars
Data bars visually represent the relative size of values within cells by
adding horizontal bars. This makes it easy to compare values at a
glance, enhancing the readability of numerical data.
from [Link] import *
# Initialize a new workbook and load an existing Excel file
workbook = Workbook()
[Link]("conditional_formatting_example.xlsx")
# Access the first worksheet in the workbook
worksheet = [Link][0]
# Create a conditional formatting rule for the range "B2:B6"
format = [Link]()
[Link]([Link]["B2:B6"])
# Define the condition for the formatting rule
condition = [Link]()
# Set the format type to data bar
[Link] = [Link]
# Use a gradient fill for the data bar
[Link] = [Link]
# Set the color of the data bar
[Link] = [Link](99, 142, 198)
# Save the modified workbook to a new file
[Link]("[Link]", ExcelVersion.Version2016)
# Release resources associated with the workbook
[Link]()
Set Data Bars Conditional Formatting in Excel in Python
Example 4: Icon Sets
Icon sets use symbols to represent data trends and categories. By
applying icons such as arrows or traffic lights, you can quickly convey
the status or comparison of values in your dataset.
from [Link] import *
# Initialize a new workbook and load an existing Excel file
workbook = Workbook()
[Link]("conditional_formatting_example.xlsx")
# Access the first worksheet in the workbook
worksheet = [Link][0]
# Create a conditional formatting rule for the range "B2:B6"
format = [Link]()
[Link]([Link]["B2:B6"])
# Define the condition for the formatting rule
condition = [Link]()
# Set the format type to icon set
[Link] = [Link]
# Define the type of icon set to four arrows
[Link] = [Link]
# Save the modified workbook to a new file
[Link]("[Link]", ExcelVersion.Version2016)
# Release resources associated with the workbook
[Link]()
Set Icon Sets Conditional Formatting in Excel in Python
Example 5: Top/Bottom Rules
Top and bottom rules allow you to highlight the highest or lowest
values in a dataset. This is useful for identifying key data points, such
as top performers or underperformers.
from [Link] import *
# Initialize a new workbook and load an existing Excel file
workbook = Workbook()
[Link]("conditional_formatting_example.xlsx")
# Access the first worksheet in the workbook
sheet = [Link][0]
# Create a conditional formatting rule for the range "B2:B6"
format_1 = [Link]()
format_1.AddRange([Link]["B2:B6"])
# Add a condition to format the top 2 ranked values in the specified range
condition_1 = format_1.AddTopBottomCondition([Link], 1)
# Set the background color for the top values to red
condition_1.BackColor = Color.get_Red()
# Create another conditional formatting rule for the range "B2:B6"
format_2 = [Link]()
format_2.AddRange([Link]["B2:B6"])
# Add a condition to format the bottom 2 ranked values in the specified range
condition_2 = format_2.AddTopBottomCondition([Link], 1)
# Set the background color for the bottom values to forest green
condition_2.BackColor = Color.get_ForestGreen()
# Save the modified workbook to a new file
[Link]("[Link]", ExcelVersion.Version2016)
# Release resources associated with the workbook
[Link]()
Set Top or Bottom Rules Conditional Formatting in Excel in Python
Example 6: Duplicate/Unique Values
This type of formatting helps identify duplicate or unique entries in
your data. It is particularly useful for data validation and ensuring data
integrity.
from [Link] import *
# Initialize a new workbook and load an existing Excel file
workbook = Workbook()
[Link]("conditional_formatting_example.xlsx")
# Access the first worksheet in the workbook
sheet = [Link][0]
# Create a conditional formatting rule for the range "B2:B6"
format_1 = [Link]()
format_1.AddRange([Link]["B2:B6"])
# Add a condition to format cells that contain duplicate values
condition_1 = format_1.AddCondition()
condition_1.FormatType = [Link]
# Set the background color for the duplicate values to light yellow
condition_1.BackColor = Color.get_LightYellow()
# Create another conditional formatting rule for the range "B2:B6"
format_2 = [Link]()
format_2.AddRange([Link]["B2:B6"])
# Add a condition to format cells that contain unique values
condition_2 = format_2.AddCondition()
condition_2.FormatType = [Link]
# Set the background color for the unique values to sky blue
condition_2.BackColor = Color.get_SkyBlue()
# Save the modified workbook to a new file
[Link]("[Link]", ExcelVersion.Version2016)
# Release resources associated with the workbook
[Link]()
Set Duplicate or Unique Values Conditional Formatting in Excel in Python
Example 7: Date-Based
Date-based conditional formatting allows you to format cells based on
specific date criteria, such as highlighting past due dates. This is
valuable for managing deadlines and timelines.
from [Link] import *
# Initialize a new workbook and load an existing Excel file
workbook = Workbook()
[Link]("conditional_formatting_example.xlsx")
# Access the first worksheet in the workbook
sheet = [Link][0]
# Create a conditional formatting rule for the range "B2:B6"
format = [Link]()
[Link]([Link]["C2:C6"])
# Add a condition to format cells that contain dates from the last month
condition = [Link]([Link])
# Set the background color for these dates to orange
[Link] = Color.get_Orange()
# Save the modified workbook to a new file
[Link]("[Link]", ExcelVersion.Version2016)
# Release resources associated with the workbook
[Link]()
Set Date Based Conditional Formatting in Excel in Python
Complete Code Example
In the complete example below, you will find how to apply numerous
types of conditional formatting to an Excel worksheet using Python
and [Link] for Python:
from [Link] import *
# Adds various types of conditional formatting to a new Excel sheet.
def AddConditionalFormattingForNewSheet(sheet):
# Add default icon sets to the sheet
AddDefaultIconSet(sheet)
AddIconSet2(sheet)
AddIconSet3(sheet)
AddIconSet4(sheet)
AddIconSet5(sheet)
AddIconSet6(sheet)
AddIconSet7(sheet)
AddIconSet8(sheet)
AddIconSet9(sheet)
AddIconSet10(sheet)
AddIconSet11(sheet)
AddIconSet12(sheet)
AddIconSet13(sheet)
AddIconSet14(sheet)
AddIconSet15(sheet)
AddIconSet16(sheet)
AddIconSet17(sheet)
AddIconSet18(sheet)
# Add default color scales
AddDefaultColorScale(sheet)
Add3ColorScale(sheet)
Add2ColorScale(sheet)
# Add various average-based conditional formatting
AddAboveAverage(sheet)
AddAboveAverage2(sheet)
AddAboveAverage3(sheet)
# Add top/bottom 10 conditional formatting
AddTop10_1(sheet)
AddTop10_2(sheet)
AddTop10_3(sheet)
AddTop10_4(sheet)
# Add data bar conditional formatting
AddDataBar1(sheet)
AddDataBar2(sheet)
# Add text-based conditional formatting
AddContainsText(sheet)
AddNotContainsText(sheet)
AddContainsBlank(sheet)
AddNotContainsBlank(sheet)
AddBeginWith(sheet)
AddEndWith(sheet)
AddContainsError(sheet)
AddNotContainsError(sheet)
AddDuplicate(sheet)
AddUnique(sheet)
# Add time period based conditional formatting
AddTimePeriod_1(sheet)
AddTimePeriod_2(sheet)
AddTimePeriod_3(sheet)
AddTimePeriod_4(sheet)
AddTimePeriod_5(sheet)
AddTimePeriod_6(sheet)
AddTimePeriod_7(sheet)
AddTimePeriod_8(sheet)
AddTimePeriod_9(sheet)
AddTimePeriod_10(sheet)
# Configure the layout of the sheet
[Link] = 15
[Link]()
# This method implements the IconSet conditional formatting type with a
ThreeArrows icon set.
def AddIconSet2(sheet):
xcfs = [Link]()
[Link]([Link]["M1:O2"])
[Link]["M1:O2"].[Link] = [Link]
[Link]["M1:O2"].[Link] = Color.get_AliceBlue()
cf = [Link]()
[Link] = [Link]
[Link] = [Link]
# Set values and labels for the icon set
[Link]["M1"].Text = "ThreeArrows"
[Link]["N1"].NumberValue = 15
[Link]["O1"].NumberValue = 18
[Link]["M2"].NumberValue = 14
[Link]["N2"].NumberValue = 17
[Link]["O2"].NumberValue = 20
# This method implements the IconSet conditional formatting type with a
FourArrows icon set.
def AddIconSet3(sheet):
xcfs = [Link]()
[Link]([Link]["M3:O4"])
[Link]["M3:O4"].[Link] = [Link]
[Link]["M3:O4"].[Link] = Color.get_AntiqueWhite()
cf = [Link]()
[Link] = [Link]
[Link] = [Link]
# Set values and labels for the FourArrows icon set
[Link]["M3"].Text = "FourArrows"
[Link]["N3"].NumberValue = 17
[Link]["O3"].NumberValue = 20
[Link]["M4"].NumberValue = 16
[Link]["N4"].NumberValue = 19
[Link]["O4"].NumberValue = 22
# This method implements the IconSet conditional formatting type with a
FiveArrows icon set.
def AddIconSet4(sheet):
xcfs = [Link]()
[Link]([Link]["M5:O6"])
[Link]["M5:O6"].[Link] = [Link]
[Link]["M5:O6"].[Link] = Color.get_Aqua()
cf = [Link]()
[Link] = [Link]
[Link] = [Link]
# Set values and labels for the FiveArrows icon set
[Link]["M5"].Text = "FiveArrows"
[Link]["N5"].NumberValue = 17
[Link]["O5"].NumberValue = 20
[Link]["M6"].NumberValue = 16
[Link]["N6"].NumberValue = 19
[Link]["O6"].NumberValue = 22
# This method implements the IconSet conditional formatting type with a
ThreeArrowsGray icon set.
def AddIconSet5(sheet):
xcfs = [Link]()
[Link]([Link]["M7:O8"])
[Link]["M7:O8"].[Link] = [Link]
[Link]["M7:O8"].[Link] = Color.get_Aquamarine()
cf = [Link]()
[Link] = [Link]
[Link] = [Link]
# Set values and labels for the ThreeArrowsGray icon set
[Link]["M7"].Text = "ThreeArrowsGray"
[Link]["N7"].NumberValue = 21
[Link]["O7"].NumberValue = 24
[Link]["M8"].NumberValue = 20
[Link]["N8"].NumberValue = 23
[Link]["O8"].NumberValue = 26
# This method implements the IconSet conditional formatting type with a
FourArrowsGray icon set.
def AddIconSet6(sheet):
xcfs = [Link]()
[Link]([Link]["M9:O10"])
[Link]["M9:O10"].[Link] = [Link]
[Link]["M9:O10"].[Link] = Color.get_Azure()
cf = [Link]()
[Link] = [Link]
[Link] = [Link]
# Set values and labels for the FourArrowsGray icon set
[Link]["M9"].Text = "FourArrowsGray"
[Link]["N9"].NumberValue = 23
[Link]["O9"].NumberValue = 26
[Link]["M10"].NumberValue = 22
[Link]["N10"].NumberValue = 25
[Link]["O10"].NumberValue = 28
# This method implements the IconSet conditional formatting type with a
FiveArrowsGray icon set.
def AddIconSet7(sheet):
xcfs = [Link]()
[Link]([Link]["M11:O12"])
[Link]["M11:O12"].[Link] = [Link]
[Link]["M11:O12"].[Link] = Color.get_Beige()
cf = [Link]()
[Link] = [Link]
[Link] = [Link]
# Set values and labels for the FiveArrowsGray icon set
[Link]["M11"].Text = "FiveArrowsGray"
[Link]["N11"].NumberValue = 25
[Link]["O11"].NumberValue = 28
[Link]["M12"].NumberValue = 24
[Link]["N12"].NumberValue = 27
[Link]["O12"].NumberValue = 30
# This method implements the IconSet conditional formatting type with a
ThreeFlags icon set.
def AddIconSet8(sheet):
xcfs = [Link]()
[Link]([Link]["M13:O14"])
[Link]["M13:O14"].[Link] = [Link]
[Link]["M13:O14"].[Link] = Color.get_Bisque()
cf = [Link]()
[Link] = [Link]
[Link] = [Link]
# Set values and labels for the ThreeFlags icon set
[Link]["M13"].Text = "ThreeFlags"
[Link]["N13"].NumberValue = 27
[Link]["O13"].NumberValue = 30
[Link]["M14"].NumberValue = 26
[Link]["N14"].NumberValue = 29
[Link]["O14"].NumberValue = 32
# This method implements the IconSet conditional formatting type with a
FiveQuarters icon set.
def AddIconSet9(sheet):
xcfs = [Link]()
[Link]([Link]["M15:O16"])
[Link]["M15:O16"].[Link] = [Link]
[Link]["M15:O16"].[Link] = Color.get_BlanchedAlmond()
cf = [Link]()
[Link] = [Link]
[Link] = [Link]
# Set values and labels for the FiveQuarters icon set
[Link]["M15"].Text = "FiveQuarters"
[Link]["N15"].NumberValue = 29
[Link]["O15"].NumberValue = 32
[Link]["M16"].NumberValue = 28
[Link]["N16"].NumberValue = 31
[Link]["O16"].NumberValue = 34
# This method implements the IconSet conditional formatting type with a
FourRating icon set.
def AddIconSet10(sheet):
xcfs = [Link]()
[Link]([Link]["M17:O18"])
[Link]["M17:O18"].[Link] = [Link]
[Link]["M17:O18"].[Link] = Color.get_LightBlue()
cf = [Link]()
[Link] = [Link]
[Link] = [Link]
# Set values and labels for the FourRating icon set
[Link]["M17"].Text = "FourRating"
[Link]["N17"].NumberValue = 31
[Link]["O17"].NumberValue = 34
[Link]["M18"].NumberValue = 30
[Link]["N18"].NumberValue = 33
[Link]["O18"].NumberValue = 36
# This method implements the IconSet conditional formatting type with a
FiveRating icon set.
def AddIconSet11(sheet):
xcfs = [Link]()
[Link]([Link]["M19:O20"])
[Link]["M19:O20"].[Link] = [Link]
[Link]["M19:O20"].[Link] = Color.get_BlueViolet()
cf = [Link]()
[Link] = [Link]
[Link] = [Link]
# Set values and labels for the FiveRating icon set
[Link]["M19"].Text = "FiveRating"
[Link]["N19"].NumberValue = 33
[Link]["O19"].NumberValue = 36
[Link]["M20"].NumberValue = 32
[Link]["N20"].NumberValue = 35
[Link]["O20"].NumberValue = 38
# This method implements the IconSet conditional formatting type with a
FourRedToBlack icon set.
def AddIconSet12(sheet):
xcfs = [Link]()
[Link]([Link]["M21:O22"])
[Link]["M21:O22"].[Link] = [Link]
[Link]["M21:O22"].[Link] = Color.get_Brown()
cf = [Link]()
[Link] = [Link]
[Link] = [Link]
# Set values and labels for the FourRedToBlack icon set
[Link]["M21"].Text = "FourRedToBlack"
[Link]["N21"].NumberValue = 35
[Link]["O21"].NumberValue = 38
[Link]["M22"].NumberValue = 34
[Link]["N22"].NumberValue = 37
[Link]["O22"].NumberValue = 40
# This method implements the IconSet conditional formatting type with a
ThreeSigns icon set.
def AddIconSet13(sheet):
xcfs = [Link]()
[Link]([Link]["M23:O24"])
[Link]["M23:O24"].[Link] = [Link]
[Link]["M23:O24"].[Link] = Color.get_BurlyWood()
cf = [Link]()
[Link] = [Link]
[Link] = [Link]
# Set values and labels for the ThreeSigns icon set
[Link]["M23"].Text = "ThreeSigns"
[Link]["N23"].NumberValue = 37
[Link]["O23"].NumberValue = 40
[Link]["M24"].NumberValue = 36
[Link]["N24"].NumberValue = 39
[Link]["O24"].NumberValue = 42
# This method implements the IconSet conditional formatting type with a
ThreeSymbols icon set.
def AddIconSet14(sheet):
xcfs = [Link]()
[Link]([Link]["M25:O26"])
[Link]["M25:O26"].[Link] = [Link]
[Link]["M25:O26"].[Link] = Color.get_CadetBlue()
cf = [Link]()
[Link] = [Link]
[Link] = [Link]
# Set values and labels for the ThreeSymbols icon set
[Link]["M25"].Text = "ThreeSymbols"
[Link]["N25"].NumberValue = 39
[Link]["O25"].NumberValue = 42
[Link]["M26"].NumberValue = 38
[Link]["N26"].NumberValue = 41
[Link]["O26"].NumberValue = 44
# This method implements the IconSet conditional formatting type with a
ThreeSymbols2 icon set.
def AddIconSet15(sheet):
xcfs = [Link]()
[Link]([Link]["M27:O28"])
[Link]["M27:O28"].[Link] = [Link]
[Link]["M27:O28"].[Link] = Color.get_Chartreuse()
cf = [Link]()
[Link] = [Link]
[Link] = IconSetType.ThreeSymbols2
# Set values and labels for the ThreeSymbols2 icon set
[Link]["M27"].Text = "ThreeSymbols2"
[Link]["N27"].NumberValue = 41
[Link]["O27"].NumberValue = 44
[Link]["M28"].NumberValue = 40
[Link]["N28"].NumberValue = 43
[Link]["O28"].NumberValue = 46
# This method implements the IconSet conditional formatting type with a
ThreeTrafficLights1 icon set.
def AddIconSet16(sheet):
xcfs = [Link]()
[Link]([Link]["M29:O30"])
[Link]["M29:O30"].[Link] = [Link]
[Link]["M29:O30"].[Link] = Color.get_Chocolate()
cf = [Link]()
[Link] = [Link]
[Link] = IconSetType.ThreeTrafficLights1
# Set values and labels for the ThreeTrafficLights1 icon set
[Link]["M29"].Text = "ThreeTrafficLights1"
[Link]["N29"].NumberValue = 43
[Link]["O29"].NumberValue = 46
[Link]["M30"].NumberValue = 42
[Link]["N30"].NumberValue = 45
[Link]["O30"].NumberValue = 48
# This method implements the IconSet conditional formatting type with a
ThreeTrafficLights2 icon set.
def AddIconSet17(sheet):
xcfs = [Link]()
[Link]([Link]["M31:O32"])
[Link]["M31:O32"].[Link] = [Link]
[Link]["M31:O32"].[Link] = Color.get_Coral()
cf = [Link]()
[Link] = [Link]
[Link] = IconSetType.ThreeTrafficLights2
# Set values and labels for the ThreeTrafficLights2 icon set
[Link]["M31"].Text = "ThreeTrafficLights2"
[Link]["N31"].NumberValue = 45
[Link]["O31"].NumberValue = 48
[Link]["M32"].NumberValue = 44
[Link]["N32"].NumberValue = 47
[Link]["O32"].NumberValue = 50
# This method implements the IconSet conditional formatting type with a
FourTrafficLights icon set.
def AddIconSet18(sheet):
xcfs = [Link]()
[Link]([Link]["M33:O35"])
[Link]["M33:O35"].[Link] = [Link]
[Link]["M33:O35"].[Link] = Color.get_CornflowerBlue()
cf = [Link]()
[Link] = [Link]
[Link] = [Link]
# Set values and labels for the FourTrafficLights icon set
[Link]["M33"].Text = "FourTrafficLights"
[Link]["N33"].NumberValue = 48
[Link]["O33"].NumberValue = 52
[Link]["M34"].NumberValue = 46
[Link]["N34"].NumberValue = 50
[Link]["O34"].NumberValue = 54
[Link]["M35"].NumberValue = 48
[Link]["N35"].NumberValue = 52
[Link]["O35"].NumberValue = 56
# This method implements the TimePeriod conditional formatting type with
Yesterday attribute.
def AddTimePeriod_10(sheet):
conds = [Link]()
[Link]([Link]["I19:K20"])
[Link]["I19:K20"].[Link] = [Link]
[Link]["I19:K20"].[Link] = Color.get_MediumSeaGreen()
cf = [Link]([Link])
[Link] = [Link]
[Link] = Color.get_Pink()
# Set date values for the Yesterday condition
c = [Link]["I19"]
c.Value2 = DateTime.get_Now().AddDays(-2).Date
c = [Link]["J19"]
c.Value2 = DateTime.get_Now().AddDays(-1).Date
c = [Link]["K19"]
c.Value2 = DateTime.get_Now().Date
c = [Link]["I20"]
[Link] = "Yesterday"
c = [Link]["J20"]
c.Value2 = DateTime.get_Now().AddDays(1).Date
c = [Link]["K20"]
c.Value2 = DateTime.get_Now().AddDays(2).Date
# This method implements the TimePeriod conditional formatting type with
Tomorrow attribute.
def AddTimePeriod_9(sheet):
conds = [Link]()
[Link]([Link]["I17:K18"])
[Link]["I17:K18"].[Link] = [Link]
[Link]["I17:K18"].[Link] = Color.get_MediumPurple()
cf = [Link]([Link])
[Link] = [Link]
[Link] = Color.get_Pink()
# Set date values for the Tomorrow condition
c = [Link]["I17"]
c.Value2 = DateTime.get_Now().AddDays(-2).Date
c = [Link]["J17"]
c.Value2 = DateTime.get_Now().AddDays(-1).Date
c = [Link]["K17"]
c.Value2 = DateTime.get_Now().Date
c = [Link]["I18"]
[Link] = "Tomorrow"
c = [Link]["J18"]
c.Value2 = DateTime.get_Now().AddDays(1).Date
c = [Link]["K18"]
c.Value2 = DateTime.get_Now().AddDays(2).Date
# This method implements the TimePeriod conditional formatting type with
ThisWeek attribute.
def AddTimePeriod_8(sheet):
conds = [Link]()
[Link]([Link]["I15:K16"])
[Link]["I15:K16"].[Link] = [Link]
[Link]["I15:K16"].[Link] = Color.get_MediumOrchid()
cf = [Link]([Link])
[Link] = [Link]
[Link] = Color.get_Pink()
# Set date values for the ThisWeek condition
c = [Link]["I15"]
c.Value2 = DateTime.get_Now().AddDays(-2).Date
c = [Link]["J15"]
c.Value2 = DateTime.get_Now().AddDays(-1).Date
c = [Link]["K15"]
c.Value2 = DateTime.get_Now().Date
c = [Link]["I16"]
[Link] = "ThisWeek"
c = [Link]["J16"]
c.Value2 = DateTime.get_Now().AddDays(2).Date
c = [Link]["K16"]
c.Value2 = DateTime.get_Now().AddDays(3).Date
# This method implements the TimePeriod conditional formatting type with
ThisMonth attribute.
def AddTimePeriod_7(sheet):
conds = [Link]()
[Link]([Link]["I13:K14"])
[Link]["I13:K14"].[Link] = [Link]
[Link]["I13:K14"].[Link] = Color.get_MediumBlue()
cf = [Link]([Link])
[Link] = [Link]
[Link] = Color.get_Pink()
# Set date values for the ThisMonth condition
c = [Link]["I13"]
c.Value2 = DateTime.get_Now().AddMonths(-1).Date
c = [Link]["J13"]
c.Value2 = DateTime.get_Now().AddDays(-1).Date
c = [Link]["K13"]
c.Value2 = DateTime.get_Now().Date
c = [Link]["I14"]
[Link] = "ThisMonth"
c = [Link]["J14"]
c.Value2 = DateTime.get_Now().AddMonths(1).Date
c = [Link]["K14"]
c.Value2 = DateTime.get_Now().AddMonths(2).Date
# This method implements the TimePeriod conditional formatting type with
NextWeek attribute.
def AddTimePeriod_6(sheet):
conds = [Link]()
[Link]([Link]["I11:K12"])
[Link]["I11:K12"].[Link] = [Link]
[Link]["I11:K12"].[Link] = Color.get_MediumAquamarine()
cf = [Link]([Link])
[Link] = [Link]
[Link] = Color.get_Pink()
# Set date values for the NextWeek condition
c = [Link]["I11"]
c.Value2 = DateTime.get_Now().AddDays(-3).Date
c = [Link]["J11"]
c.Value2 = DateTime.get_Now().AddDays(-2).Date
c = [Link]["K11"]
c.Value2 = DateTime.get_Now().Date
c = [Link]["I12"]
[Link] = "NextWeek"
c = [Link]["J12"]
c.Value2 = DateTime.get_Now().AddDays(3).Date
c = [Link]["K12"]
c.Value2 = DateTime.get_Now().AddMonths(4).Date
# This method implements the TimePeriod conditional formatting type with
NextMonth attribute.
def AddTimePeriod_5(sheet):
conds = [Link]()
[Link]([Link]["I9:K10"])
[Link]["I9:K10"].[Link] = [Link]
[Link]["I9:K10"].[Link] = Color.get_Maroon()
cf = [Link]([Link])
[Link] = [Link]
[Link] = Color.get_Pink()
# Set date values for the NextMonth condition
c = [Link]["I9"]
c.Value2 = DateTime.get_Now().AddDays(-3).Date
c = [Link]["J9"]
c.Value2 = DateTime.get_Now().AddMonths(-1).Date
c = [Link]["K9"]
c.Value2 = DateTime.get_Now().Date
c = [Link]["I10"]
[Link] = "NextMonth"
c = [Link]["J10"]
c.Value2 = DateTime.get_Now().AddMonths(1).Date
c = [Link]["K10"]
c.Value2 = DateTime.get_Now().AddMonths(2).Date
# This method implements the TimePeriod conditional formatting type with
LastWeek attribute.
def AddTimePeriod_4(sheet):
conds = [Link]()
[Link]([Link]["I7:K8"])
[Link]["I7:K8"].[Link] = [Link]
[Link]["I7:K8"].[Link] = Color.get_Linen()
cf = [Link]([Link])
[Link] = [Link]
[Link] = Color.get_Pink()
# Set date values for the LastWeek condition
c = [Link]["I7"]
c.Value2 = DateTime.get_Now().AddDays(-6).Date
c = [Link]["J7"]
c.Value2 = DateTime.get_Now().AddDays(-5).Date
c = [Link]["K7"]
c.Value2 = DateTime.get_Now().Date
c = [Link]["I8"]
[Link] = "LastWeek"
c = [Link]["J8"]
c.Value2 = DateTime.get_Now().AddDays(3).Date
c = [Link]["K8"]
c.Value2 = DateTime.get_Now().AddMonths(4).Date
# This method implements the TimePeriod conditional formatting type with
LastMonth attribute.
def AddTimePeriod_3(sheet):
conds = [Link]()
[Link]([Link]["I5:K6"])
[Link]["I5:K6"].[Link] = [Link]
[Link]["I5:K6"].[Link] = Color.get_Linen()
cf = [Link]([Link])
[Link] = [Link]
[Link] = Color.get_Pink()
# Set date values for the LastMonth condition
c = [Link]["I5"]
c.Value2 = DateTime.get_Now().AddDays(-6).Date
c = [Link]["J5"]
c.Value2 = DateTime.get_Now().AddMonths(-1).Date
c = [Link]["K5"]
c.Value2 = DateTime.get_Now().Date
c = [Link]["I6"]
[Link] = "LastMonth"
c = [Link]["J6"]
c.Value2 = DateTime.get_Now().AddDays(3).Date
c = [Link]["K6"]
c.Value2 = DateTime.get_Now().AddMonths(1).Date
# This method implements the TimePeriod conditional formatting type with
Last7Days attribute.
def AddTimePeriod_2(sheet):
conds = [Link]()
[Link]([Link]["I3:K4"])
[Link]["I3:K4"].[Link] = [Link]
[Link]["I3:K4"].[Link] = Color.get_LightSkyBlue()
cf = [Link](TimePeriodType.Last7Days)
[Link] = [Link]
[Link] = Color.get_Pink()
# Set date values for the Last7Days condition
c = [Link]["I3"]
c.Value2 = DateTime.get_Now().AddDays(-8).Date
c = [Link]["J3"]
c.Value2 = DateTime.get_Now().AddDays(-7).Date
c = [Link]["K3"]
c.Value2 = DateTime.get_Now().Date
c = [Link]["I4"]
[Link] = "Last7Days"
c = [Link]["J4"]
c.Value2 = DateTime.get_Now().AddDays(3).Date
c = [Link]["K4"]
c.Value2 = DateTime.get_Now().AddMonths(2).Date
# This method implements the TimePeriod conditional formatting type with
Today attribute.
def AddTimePeriod_1(sheet):
conds = [Link]()
[Link]([Link]["I1:K2"])
[Link]["I1:K2"].[Link] = [Link]
[Link]["I1:K2"].[Link] = Color.get_LightSlateGray()
cf = [Link]([Link])
[Link] = [Link]
[Link] = Color.get_Pink()
# Set date values for the Today condition
c = [Link]["I1"]
c.Value2 = DateTime.get_Now().AddDays(-8).Date
c = [Link]["J1"]
c.Value2 = DateTime.get_Now().AddDays(-7).Date
c = [Link]["K1"]
c.Value2 = DateTime.get_Now().Date
c = [Link]["I2"]
[Link] = "Today"
c = [Link]["J2"]
c.Value2 = DateTime.get_Now().AddDays(3).Date
c = [Link]["K2"]
c.Value2 = DateTime.get_Now().AddMonths(2).Date
# This method implements the DuplicateValues conditional formatting type.
def AddDuplicate(sheet):
conds = [Link]()
[Link]([Link]["E23:G24"])
[Link]["E23:G24"].[Link] = [Link]
[Link]["E23:G24"].[Link] = Color.get_LightSlateGray()
cf = [Link]()
[Link] = [Link]
[Link] = Color.get_Pink()
# Set values for the Duplicate condition
c = [Link]["E23"]
[Link] = "aa"
c = [Link]["F23"]
[Link] = "bb"
c = [Link]["G23"]
[Link] = "aa"
c = [Link]["E24"]
[Link] = "bbb"
c = [Link]["F24"]
[Link] = "bb"
c = [Link]["G24"]
[Link] = "ccc"
# This method implements the UniqueValues conditional formatting type.
def AddUnique(sheet):
conds = [Link]()
[Link]([Link]["E21:G22"])
[Link]["E21:G22"].[Link] = [Link]
[Link]["E21:G22"].[Link] = Color.get_LightSalmon()
cf = [Link]()
[Link] = [Link]
[Link] = Color.get_Yellow()
# Set values for the Unique condition
c = [Link]["E21"]
[Link] = "aa"
c = [Link]["F21"]
[Link] = "bb"
c = [Link]["G21"]
[Link] = "aa"
c = [Link]["E22"]
[Link] = "bbb"
c = [Link]["F22"]
[Link] = "bb"
c = [Link]["G22"]
[Link] = "ccc"
# This method implements the NotContainsError conditional formatting type.
def AddNotContainsError(sheet):
conds = [Link]()
[Link]([Link]["E19:G20"])
[Link]["E19:G20"].[Link] = [Link]
[Link]["E19:G20"].[Link] = Color.get_LightSeaGreen()
cf = [Link]()
[Link] = [Link]
[Link] = Color.get_Yellow()
# Set values for the NotContainsError condition
c = [Link]["E19"]
[Link] = "aa"
c = [Link]["F19"]
[Link] = "=Sum"
c = [Link]["G19"]
[Link] = "aa"
c = [Link]["E20"]
[Link] = "bbb"
c = [Link]["F20"]
[Link] = "sss"
c = [Link]["G20"]
[Link] = "=Max"
# This method implements the ContainsErrors conditional formatting type.
def AddContainsError(sheet):
conds = [Link]()
[Link]([Link]["E17:G18"])
[Link]["E17:G18"].[Link] = [Link]
[Link]["E17:G18"].[Link] = Color.get_LightSkyBlue()
cf = [Link]()
[Link] = [Link]
[Link] = Color.get_Yellow()
# Set values for the ContainsError condition
c = [Link]["E17"]
[Link] = "aa"
c = [Link]["F17"]
[Link] = "=Sum"
c = [Link]["G17"]
[Link] = "aa"
c = [Link]["E18"]
[Link] = "bbb"
c = [Link]["F18"]
[Link] = "sss"
c = [Link]["G18"]
[Link] = "=Max"
# This method implements the BeginWith conditional formatting type.
def AddBeginWith(sheet):
conds = [Link]()
[Link]([Link]["E15:G16"])
[Link]["E15:G16"].[Link] = [Link]
[Link]["E15:G16"].[Link] = Color.get_LightGoldenrodYellow()
cf = [Link]("ab")
[Link] = [Link]
[Link] = Color.get_Pink()
# Set values for the BeginWith condition
c = [Link]["E15"]
[Link] = "aa"
c = [Link]["F15"]
[Link] = "abc"
c = [Link]["G15"]
[Link] = "aa"
c = [Link]["E16"]
[Link] = "bbb"
c = [Link]["F16"]
[Link] = "sss"
c = [Link]["G16"]
[Link] = "abcd"
# This method implements the EndWith conditional formatting type.
def AddEndWith(sheet):
conds = [Link]()
[Link]([Link]["E13:G14"])
[Link]["E13:G14"].[Link] = [Link]
[Link]["E13:G14"].[Link] = Color.get_LightGray()
cf = [Link]("ab")
[Link] = [Link]
[Link] = Color.get_Yellow()
# Set values for the EndWith condition
c = [Link]["E13"]
[Link] = "aa"
c = [Link]["F13"]
[Link] = "abc"
c = [Link]["G13"]
[Link] = "aab"
c = [Link]["E14"]
[Link] = "bbbc"
c = [Link]["F14"]
[Link] = "sab"
c = [Link]["G14"]
[Link] = "abcd"
# This method implements the NotContainsBlank conditional formatting type.
def AddNotContainsBlank(sheet):
conds = [Link]()
[Link]([Link]["E11:G12"])
[Link]["E11:G12"].[Link] = [Link]
[Link]["E11:G12"].[Link] = Color.get_LightCoral()
cf = [Link]()
[Link] = [Link]
[Link] = Color.get_Pink()
# Set values for the NotContainsBlank condition
c = [Link]["E11"]
[Link] = "aa"
c = [Link]["F11"]
[Link] = " "
c = [Link]["G11"]
[Link] = "aab"
c = [Link]["E12"]
[Link] = "abc"
c = [Link]["F12"]
[Link] = " "
c = [Link]["G12"]
[Link] = "abcd"
# This method implements the ContainsBlank conditional formatting type.
def AddContainsBlank(sheet):
conds = [Link]()
[Link]([Link]["E9:G10"])
[Link]["E9:G10"].[Link] = [Link]
[Link]["E9:G10"].[Link] = Color.get_LightCyan()
cf = [Link]()
[Link] = [Link]
[Link] = Color.get_Yellow()
# Set values for the ContainsBlank condition
c = [Link]["E9"]
[Link] = "aa"
c = [Link]["F9"]
[Link] = " "
c = [Link]["G9"]
[Link] = "aab"
c = [Link]["E10"]
[Link] = "abc"
c = [Link]["F10"]
[Link] = "dvdf"
c = [Link]["G10"]
[Link] = "abcd"
# This method implements the NotContainsText conditional formatting type.
def AddNotContainsText(sheet):
conds = [Link]()
[Link]([Link]["E7:G8"])
[Link]["E7:G8"].[Link] = [Link]
[Link]["E7:G8"].[Link] = Color.get_LightGreen()
cf = [Link]("abc")
[Link] = [Link]
[Link] = Color.get_Pink()
# Set values for the NotContainsText condition
c = [Link]["E7"]
[Link] = "aa"
c = [Link]["F7"]
[Link] = "abfd"
c = [Link]["G7"]
[Link] = "aab"
c = [Link]["E8"]
[Link] = "abc"
c = [Link]["F8"]
[Link] = "cedf"
c = [Link]["G8"]
[Link] = "abcd"
# This method implements the ContainsText conditional formatting type.
def AddContainsText(sheet):
conds = [Link]()
[Link]([Link]["E5:G6"])
[Link]["E5:G6"].[Link] = [Link]
[Link]["E5:G6"].[Link] = Color.get_LightBlue()
cf = [Link]("abc")
[Link] = [Link]
[Link] = Color.get_Yellow()
# Set values for the ContainsText condition
c = [Link]["E5"]
[Link] = "aa"
c = [Link]["F5"]
[Link] = "abfd"
c = [Link]["G5"]
[Link] = "aab"
c = [Link]["E6"]
[Link] = "abc"
c = [Link]["F6"]
[Link] = "cedf"
c = [Link]["G6"]
[Link] = "abcd"
# This method implements the DataBars conditional formatting type with
Percentile attribute.
def AddDataBar2(sheet):
# Add data bars
xcfs = [Link]()
[Link]([Link]["E3:G4"])
[Link]["E3:G4"].[Link] = [Link]
[Link]["E3:G4"].[Link] = Color.get_LightGreen()
cf = [Link]()
[Link] = [Link]
[Link] = Color.get_Orange()
[Link] = [Link]
[Link] = Double(30.78)
[Link] = False
# Set numeric values for data bars
c = [Link]["E3"]
[Link] = 6
c = [Link]["F3"]
[Link] = 9
c = [Link]["G3"]
[Link] = 12
c = [Link]["E4"]
[Link] = 8
c = [Link]["F4"]
[Link] = 11
c = [Link]["G4"]
[Link] = 14
# This method implements the DataBars conditional formatting type.
def AddDataBar1(sheet):
# Add data bars
xcfs = [Link]()
[Link]([Link]["E1:G2"])
[Link]["E1:G2"].[Link] = [Link]
[Link]["E1:G2"].[Link] = Color.get_YellowGreen()
cf = [Link]()
[Link] = [Link]
[Link] = Color.get_Blue()
[Link] = [Link]
[Link] = True
# Set numeric values for data bars
c = [Link]["E1"]
[Link] = 4
c = [Link]["F1"]
[Link] = 7
c = [Link]["G1"]
[Link] = 10
c = [Link]["E2"]
[Link] = 6
c = [Link]["F2"]
[Link] = 9
c = [Link]["G2"]
[Link] = 14
# This method implements the IconSet conditional formatting type.
def AddDefaultIconSet(sheet):
xcfs = [Link]()
[Link]([Link]["A1:C2"])
[Link]["A1:C2"].[Link] = [Link]
[Link]["A1:C2"].[Link] = Color.get_Yellow()
cf = [Link]()
[Link] = [Link]
# Set numeric values for the default icon set
[Link]["A1"].NumberValue = 0
[Link]["B1"].NumberValue = 3
[Link]["C1"].NumberValue = 6
[Link]["A2"].NumberValue = 2
[Link]["B2"].NumberValue = 5
[Link]["C2"].NumberValue = 8
# This method implements the ColorScale conditional formatting type.
def AddDefaultColorScale(sheet):
xcfs = [Link]()
[Link]([Link]["A5:C6"])
[Link]["A5:C6"].[Link] = [Link]
[Link]["A5:C6"].[Link] = Color.get_Pink()
cf = [Link]()
[Link] = [Link]
# Set numeric values for the color scale
[Link]["A5"].NumberValue = 4
[Link]["B5"].NumberValue = 7
[Link]["C5"].NumberValue = 10
[Link]["A6"].NumberValue = 6
[Link]["B6"].NumberValue = 9
[Link]["C6"].NumberValue = 12
# This method implements the ColorScale conditional formatting type with some
color scale attributes.
def Add3ColorScale(sheet):
xcfs = [Link]()
[Link]([Link]["A7:C8"])
[Link]["A7:C8"].[Link] = [Link]
[Link]["A7:C8"].[Link] = Color.get_Green()
cf = [Link]()
[Link] = [Link]
[Link] = [Link]
[Link] = Int32(9)
[Link] = Color.get_Purple()
# Set numeric values for the color scale
[Link]["A7"].NumberValue = 6
[Link]["B7"].NumberValue = 9
[Link]["C7"].NumberValue = 12
[Link]["A8"].NumberValue = 8
[Link]["B8"].NumberValue = 11
[Link]["C8"].NumberValue = 14
# This method implements the ColorScale conditional formatting type with some
color scale attributes.
def Add2ColorScale(sheet):
xcfs = [Link]()
[Link]([Link]["A9:C10"])
[Link]["A9:C10"].[Link] = [Link]
[Link]["A9:C10"].[Link] = Color.get_White()
cf = [Link]()
[Link] = [Link]
[Link] = Color.get_Gold()
[Link] = Color.get_SkyBlue()
# Set numeric values for the color scale
[Link]["A9"].NumberValue = 8
[Link]["B9"].NumberValue = 12
[Link]["C9"].NumberValue = 13
[Link]["A10"].NumberValue = 10
[Link]["B10"].NumberValue = 13
[Link]["C10"].NumberValue = 16
# This method implements the AboveAverage conditional formatting type.
def AddAboveAverage(sheet):
conds = [Link]()
[Link]([Link]["A11:C12"])
[Link]["A11:C12"].[Link] = [Link]
[Link]["A11:C12"].[Link] = Color.get_Tomato()
cf = [Link]([Link])
[Link] = [Link]
[Link] = Color.get_Pink()
# Set numeric values for the AboveAverage condition
[Link]["A11"].NumberValue = 10
[Link]["B11"].NumberValue = 13
[Link]["C11"].NumberValue = 16
[Link]["A12"].NumberValue = 12
[Link]["B12"].NumberValue = 15
[Link]["C12"].NumberValue = 18
# This method implements an BelowEqualAverage conditional formatting type
with some custom attributes.
def AddAboveAverage2(sheet):
conds = [Link]()
[Link]([Link]["A13:C14"])
[Link]["A13:C14"].[Link] = [Link]
[Link]["A13:C14"].[Link] = Color.get_LightPink()
cf = [Link]([Link])
[Link] = [Link]
[Link] = Color.get_LightSkyBlue()
# Set numeric values for the AboveAverage2 condition
[Link]["A13"].NumberValue = 12
[Link]["B13"].NumberValue = 15
[Link]["C13"].NumberValue = 18
[Link]["A14"].NumberValue = 14
[Link]["B14"].NumberValue = 17
[Link]["C14"].NumberValue = 20
# This method implements an AboveStdDev3 conditional formatting type with
some custom attributes.
def AddAboveAverage3(sheet):
conds = [Link]()
[Link]([Link]["A15:C16"])
[Link]["A15:C16"].[Link] = [Link]
[Link]["A15:C16"].[Link] = Color.get_LightPink()
cf = [Link](AverageType.AboveStdDev3)
[Link] = [Link]
[Link] = Color.get_LightSkyBlue()
# Set numeric values for the AboveAverage3 condition
[Link]["A15"].NumberValue = 12
[Link]["B15"].NumberValue = 15
[Link]["C15"].NumberValue = 18
[Link]["A16"].NumberValue = 14
[Link]["B16"].NumberValue = 17
[Link]["C16"].NumberValue = 20
# This method implements a Top10 conditional formatting type.
def AddTop10_1(sheet):
conds = [Link]()
[Link]([Link]["A17:C20"])
[Link]["A17:C20"].[Link] = [Link]
[Link]["A17:C20"].[Link] = Color.get_Gray()
cf = [Link]([Link], 10)
[Link] = [Link]
[Link] = Color.get_Yellow()
# Set numeric values for the Top10 condition
[Link]["A17"].NumberValue = 16
[Link]["B17"].NumberValue = 21
[Link]["C17"].NumberValue = 26
[Link]["A18"].NumberValue = 18
[Link]["B18"].NumberValue = 23
[Link]["C18"].NumberValue = 28
[Link]["A19"].NumberValue = 20
[Link]["B19"].NumberValue = 25
[Link]["C19"].NumberValue = 30
[Link]["A20"].NumberValue = 22
[Link]["B20"].NumberValue = 27
[Link]["C20"].NumberValue = 32
# This method implements Bottom 10 conditional formatting type.
def AddTop10_2(sheet):
conds = [Link]()
[Link]([Link]["A21:C24"])
[Link]["A21:C24"].[Link] = [Link]
[Link]["A21:C24"].[Link] = Color.get_Green()
cf = [Link]([Link], 10)
[Link] = [Link]
[Link] = Color.get_Pink()
# Set numeric values for the Top10_2 condition
[Link]["A21"].NumberValue = 20
[Link]["B21"].NumberValue = 25
[Link]["C21"].NumberValue = 30
[Link]["A22"].NumberValue = 22
[Link]["B22"].NumberValue = 27
[Link]["C22"].NumberValue = 32
[Link]["A23"].NumberValue = 24
[Link]["B23"].NumberValue = 29
[Link]["C23"].NumberValue = 34
[Link]["A24"].NumberValue = 24
[Link]["B24"].NumberValue = 31
[Link]["C24"].NumberValue = 36
# This method implements TopPercent 10 conditional formatting type with some
custom attributes.
def AddTop10_3(sheet):
conds = [Link]()
[Link]([Link]["A25:C28"])
[Link]["A25:C28"].[Link] = [Link]
[Link]["A25:C28"].[Link] = Color.get_Orange()
cf = [Link]([Link], 10)
[Link] = [Link]
[Link] = Color.get_Blue()
# Set numeric values for the Top10_3 condition
[Link]["A25"].NumberValue = 24
[Link]["B25"].NumberValue = 29
[Link]["C25"].NumberValue = 34
[Link]["A26"].NumberValue = 25
[Link]["B26"].NumberValue = 36
[Link]["C26"].NumberValue = 32
[Link]["A27"].NumberValue = 24
[Link]["B27"].NumberValue = 28
[Link]["C27"].NumberValue = 31
[Link]["A28"].NumberValue = 34
[Link]["B28"].NumberValue = 26
[Link]["C28"].NumberValue = 32
# This method implements BottomPercent 10 conditional formatting type with
some custom attributes.
def AddTop10_4(sheet):
conds = [Link]()
[Link]([Link]["A29:C32"])
[Link]["A29:C32"].[Link] = [Link]
[Link]["A29:C32"].[Link] = Color.get_Gold()
cf = [Link]([Link], 10)
[Link] = [Link]
[Link] = Color.get_Green()
# Set numeric values for the Top10_4 condition
[Link]["A29"].NumberValue = 22
[Link]["B29"].NumberValue = 33
[Link]["C29"].NumberValue = 38
[Link]["A30"].NumberValue = 30
[Link]["B30"].NumberValue = 35
[Link]["C30"].NumberValue = 39
[Link]["A31"].NumberValue = 32
[Link]["B31"].NumberValue = 37
[Link]["C31"].NumberValue = 43
[Link]["A32"].NumberValue = 34
[Link]["B32"].NumberValue = 28
[Link]["C32"].NumberValue = 32
# Set the output file name
outputFile = "[Link]"
# Load the document from disk and create a new worksheet
workbook = Workbook()
[Link](1)
sheet = [Link][0]
# Apply conditional formatting to the new sheet
AddConditionalFormattingForNewSheet(sheet)
# Save the workbook to file
[Link](outputFile, ExcelVersion.Version2016)
[Link]()
Add Numerous Conditional Formatting to Excel in Python
Conclusion
Mastering conditional formatting in Excel using Python can greatly
enhance your data analysis capabilities. With the [Link] for Python
library, you can automate the application of various formatting rules,
making your reports more visually appealing and easier to interpret.
Additional Resource
[Link] for Python Documentation
More Related Topics to Read
Apply or Remove Row and Column Grouping in Excel with Python
Python — How to Convert Excel XLS or XLSX to PDF
Apply or Remove Filters in Excel with Python (Comprehensive
Guide)
Create, Update and Remove Pivot Tables in Excel with Python