Category / Section
Can we set multiple conditional formatting using XlsIO?
1 min read
Yes, we can set multiple conditional formatting using XlsIO. Use the following code snippets to set multiple conditional formatting.
C#
//Applying conditional formatting to "A1:C5" for format type as CellValue( Between) IConditionalFormats condition = sheet.Range["A1:C5"].ConditionalFormats; //Adding formats to IConditionalFormats collection IConditionalFormat condition1 = condition.AddCondition(); condition1.FirstFormula = "5"; condition1.SecondFormula = "10"; //Setting format properties. condition1.Operator = ExcelComparisonOperator.Between; condition1.FormatType = ExcelCFType.CellValue; condition1.BackColorRGB = Color.FromArgb(238, 122, 3); condition1.IsBold = true; condition1.IsItalic = true; //Applying conditional formatting to "A1:C5" for format type as CellValue( Equal) IConditionalFormats condition2 = sheet.Range["A1:C5"].ConditionalFormats; //Adding formats to IConditionalFormats collection IConditionalFormat condition3 = condition2.AddCondition(); //Setting format properties. condition3.FormatType = ExcelCFType.CellValue; condition3.Operator = ExcelComparisonOperator.Equal; condition3.FirstFormula = "20"; condition3.FontColorRGB = Color.FromArgb(0xde, 0x64, 0x13);
VB
'Applying conditional formatting to "A1:C5" for format type as CellValue( Between) Dim condition As IConditionalFormats = sheet.Range("A1:C5").ConditionalFormats 'Adding formats to IConditionalFormats collection Dim condition1 As IConditionalFormat = condition.AddCondition() condition1.FirstFormula = "5" condition1.SecondFormula = "10" 'Setting format properties. condition1.Operator = ExcelComparisonOperator.Between condition1.FormatType = ExcelCFType.CellValue condition1.BackColorRGB = Color.FromArgb(238, 122, 3) condition1.IsBold = True condition1.IsItalic = True 'Applying conditional formatting to "A1:C5" for format type as CellValue( Equal) Dim condition2 As IConditionalFormats = sheet.Range("A1:C5").ConditionalFormats 'Adding formats to IConditionalFormats collection Dim condition3 As IConditionalFormat = condition2.AddCondition() 'Setting format properties. condition3.FormatType = ExcelCFType.CellValue condition3.Operator = ExcelComparisonOperator.Equal condition3.FirstFormula = "20" condition3.FontColorRGB = Color.FromArgb(&HDE, &H64, &H13)
Here is the sample for your reference:
Multiple_ConditionalFormatting.zip