Bedingte Formatierung in 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
Bedingte Formatierung in Excel

Bedingte Formatierung in Excel

IronXL for Python unterstützt bedingte Formatierung von Zellen und Bereichen. Mit der bedingten Formatierung wird der Stil einer Zelle - wie Hintergrundfarbe oder Textformatierung - basierend auf logischen oder programmatischen Regeln geändert.

Verwenden Sie CreateConditionalFormattingRule(formula), um eine Regel zur bedingten Formatierung basierend auf einem Booleschen Ausdruck zu erstellen. Wenn die Formel zu True ausgewertet wird, wird die Zelle hervorgehoben. Die bereitgestellte Formel muss ein boolesches Ergebnis zurückgeben.

Die Überladung von CreateConditionalFormattingRule mit drei Parametern akzeptiert nur ComparisonOperator.Between oder ComparisonOperator.NotBetween als ersten Parameter.

Die bedingte Formatierung ermöglicht es Entwicklern, Zellen und Bereiche mit spezifischen Farb- und Formatkombinationen hervorzuheben, abhängig vom Wert jeder Zelle. Dies macht es einfach, Daten zu analysieren, Probleme zu erkennen und Muster und Trends direkt innerhalb der Excel-Datei zu identifizieren.

Lernen Sie, wie man die bedingte Formatierung in Python anwendet

Bereit loszulegen?

Version:2026.11gerade veröffentlicht