Excelの条件付き書式
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の条件付き書式

Excelの条件付き書式

IronXL for Pythonはセルや範囲の条件付き書式をサポートしています。 条件付き書式は、論理的またはプログラム的なルールに基づいて、セルのスタイル(背景色やテキストの書式設定など)を変更します。

CreateConditionalFormattingRule(formula) を使用して、ブール式に基づいた条件付き書式のルールを作成します。 数式が True に評価されると、セルが強調表示されます。 提供された式は必ずBooleanの結果を返す必要があります。

CreateConditionalFormattingRule の3つのパラメーターオーバーロードは、最初のパラメーターとして ComparisonOperator.Between または ComparisonOperator.NotBetween のみを受け付けます。

条件付き書式は、開発者が特定の色とフォーマットの組み合わせでセルや範囲を強調表示することを可能にします。 これにより、Excel ファイル内で直接データを分析し、問題を検出し、パターンやトレンドを識別することが容易になります。

Pythonで条件付き書式を適用する方法を学びます

準備はできましたか?

バージョン:2026.11ちょうどリリースされました