FormatConditionCollection

FormatConditionCollection class

steht für bedingte Formatierung. Die FormatConditions können bis zu drei bedingte Formatierungen enthalten.

public class FormatConditionCollection

Eigenschaften

NameBeschreibung
Count { get; }Ruft die Anzahl der Bedingungen ab.
Item { get; }Ruft die Formatierungsbedingung nach Index ab.
RangeCount { get; }Ruft die Anzahl der bedingt formatierten Bereiche ab.

Methoden

NameBeschreibung
Add(CellArea, FormatConditionType, OperatorType, string, string)Fügt eine Formatierungsbedingung und einen betroffenen Zellbereich zu den FormatConditions hinzu Die FormatConditions können bis zu drei bedingte Formatierungen enthalten. Verweise auf die anderen Blätter sind in den Formeln der bedingten Formatierung nicht erlaubt.
AddArea(CellArea)Fügt einen bedingt formatierten Zellbereich hinzu.
AddCondition(FormatConditionType)Fügt eine Formatbedingung hinzu.
AddCondition(FormatConditionType, OperatorType, string, string)Fügt eine Formatierungsbedingung hinzu.
GetCellArea(int)Ruft den bedingt formatierten Zellbereich nach Index ab.
RemoveArea(int)Entfernt bedingt formatierten Zellbereich nach Index.
RemoveArea(int, int, int, int)Bedingte Formatierung im Bereich entfernen.
RemoveCondition(int)Entfernt die Formatierungsbedingung nach Index.

Beispiele


[C#]

//Eine neue Arbeitsmappe erstellen.
Workbook workbook = new Workbook();

// Holen Sie sich das erste Arbeitsblatt.
Worksheet sheet = workbook.Worksheets[0];

//Fügt eine leere bedingte Formatierung hinzu
int index = sheet.ConditionalFormattings.Add();
FormatConditionCollection fcs = sheet.ConditionalFormattings[index];
//Legt den bedingten Formatbereich fest.
CellArea ca = new CellArea();
ca.StartRow = 0;
ca.EndRow = 0;
ca.StartColumn = 0;
ca.EndColumn = 0;
fcs.AddArea(ca);
ca = new CellArea();
ca.StartRow = 1;
ca.EndRow = 1;
ca.StartColumn = 1;
ca.EndColumn = 1;
fcs.AddArea(ca);
//Bedingung hinzufügen.
int conditionIndex = fcs.AddCondition(FormatConditionType.CellValue, OperatorType.Between, "=A2", "100");
//Bedingung hinzufügen.
int conditionIndex2 = fcs.AddCondition(FormatConditionType.CellValue, OperatorType.Between, "50", "100");
//Setzt die Hintergrundfarbe.
FormatCondition fc = fcs[conditionIndex];
fc.Style.BackgroundColor = Color.Red;
//Speichern der Excel-Datei
workbook.Save("output.xls");   

[Visual Basic]

'Instanziieren eines Workbook-Objekts
Dim workbook As Workbook = New Workbook()
Dim sheet As Worksheet = workbook.Worksheets(0)
' Fügt eine leere bedingte Formatierung hinzu
Dim index As Integer = sheet.ConditionalFormattings.Add()
Dim fcs As FormatConditionCollection = sheet.ConditionalFormattings(index)
'Legt den bedingten Formatbereich fest.
Dim ca As CellArea = New CellArea()
ca.StartRow = 0
ca.EndRow = 0
ca.StartColumn = 0
ca.EndColumn = 0
fcs.AddArea(ca)
ca = New CellArea()
ca.StartRow = 1
ca.EndRow = 1
ca.StartColumn = 1
ca.EndColumn = 1
fcs.AddArea(ca)
'Fügt Bedingung hinzu.
Dim conditionIndex As Integer = fcs.AddCondition(FormatConditionType.CellValue, OperatorType.Between, "=A2", "100")
'Fügt Bedingung hinzu.
Dim conditionIndex2 As Integer = fcs.AddCondition(FormatConditionType.CellValue, OperatorType.Between, "50", "100")
'Legt die Hintergrundfarbe fest.
Dim fc As FormatCondition = fcs(conditionIndex)
fc.Style.BackgroundColor = Color.Red
'Speichern der Excel-Datei
workbook.Save("output.xls")

Siehe auch