ConditionalFormattingCollection

ConditionalFormattingCollection class

Encapsula una colección deFormatCondition objetos.

public class ConditionalFormattingCollection : CollectionBase<FormatConditionCollection>

Propiedades

NombreDescripción
Capacity { get; set; }
Count { get; }
Item { get; }Obtiene el elemento FormatConditions en el índice especificado.
Item { get; set; }

Métodos

NombreDescripción
Add()Agrega FormatConditions a la colección.
BinarySearch(FormatConditionCollection)
BinarySearch(FormatConditionCollection, IComparer<FormatConditionCollection>)
BinarySearch(int, int, FormatConditionCollection, IComparer<FormatConditionCollection>)
Clear()
Contains(FormatConditionCollection)
Copy(ConditionalFormattingCollection)Copia formato condicional.
CopyTo(FormatConditionCollection[])
CopyTo(FormatConditionCollection[], int)
CopyTo(int, FormatConditionCollection[], int, int)
Exists(Predicate<FormatConditionCollection>)
Find(Predicate<FormatConditionCollection>)
FindAll(Predicate<FormatConditionCollection>)
FindIndex(Predicate<FormatConditionCollection>)
FindIndex(int, Predicate<FormatConditionCollection>)
FindIndex(int, int, Predicate<FormatConditionCollection>)
FindLast(Predicate<FormatConditionCollection>)
FindLastIndex(Predicate<FormatConditionCollection>)
FindLastIndex(int, Predicate<FormatConditionCollection>)
FindLastIndex(int, int, Predicate<FormatConditionCollection>)
GetEnumerator()
IndexOf(FormatConditionCollection)
IndexOf(FormatConditionCollection, int)
IndexOf(FormatConditionCollection, int, int)
LastIndexOf(FormatConditionCollection)
LastIndexOf(FormatConditionCollection, int)
LastIndexOf(FormatConditionCollection, int, int)
RemoveArea(int, int, int, int)Eliminar todo el formato condicional en el rango.
RemoveAt(int)

Ejemplos


[C#]

// Instanciando un objeto Workbook
Workbook workbook = new Workbook();

Worksheet sheet = workbook.Worksheets[0];

//Obtener formato condicional
ConditionalFormattingCollection cformattings = sheet.ConditionalFormattings;

//Agrega un formato condicional vacío
int index = cformattings.Add();

// Obtener el formato condicional recién agregado
FormatConditionCollection fcs = cformattings[index];

//Establece el rango de formato condicional.
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);

//Añadir condición.
int conditionIndex = fcs.AddCondition(FormatConditionType.CellValue, OperatorType.Between, "=A2", "100");

//Añadir condición.
int conditionIndex2 = fcs.AddCondition(FormatConditionType.CellValue, OperatorType.Between, "50", "100");

//Establece el color de fondo.
FormatCondition fc = fcs[conditionIndex];

fc.Style.BackgroundColor = Color.Red;

//Guardando el archivo de Excel
workbook.Save("output.xls");

[VB.NET]

'Crear una instancia de un objeto Workbook
DDim workbook As Workbook = New Workbook()

Dim sheet As Worksheet = workbook.Worksheets(0)

'Obtener formato condicional
Dim cformattings As ConditionalFormattingCollection = sheet.ConditionalFormattings

'Agrega un formato condicional vacío
Dim index As Integer = cformattings.Add()

'Obtenga el formato condicional recién agregado
Dim fcs As FormatConditionCollection = cformattings(index)

'Establece el rango de formato condicional.
Dim ca As 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)

'Añadir condición.
Dim conditionIndex As Integer = fcs.AddCondition(FormatConditionType.CellValue, OperatorType.Between, "=A2", "100")

'Añadir condición.
Dim conditionIndex2 As Integer = fcs.AddCondition(FormatConditionType.CellValue, OperatorType.Between, "50", "100")

'Establece el color de fondo.
Dim fc As FormatCondition = fcs(conditionIndex)

fc.Style.BackgroundColor = Color.Red

'Guardar el archivo de Excel
workbook.Save("output.xls")

Ver también