Syncfusion.XlsIO.Base
Example 


FormatType Property (IConditionalFormat)

Gets or sets the type of the conditional format.
Syntax
'Declaration
 
Property FormatType As ExcelCFType
'Usage
 
Dim instance As IConditionalFormat
Dim value As ExcelCFType
 
instance.FormatType = value
 
value = instance.FormatType
ExcelCFType FormatType {get; set;}
Remarks
By default the FormatType is set to ExcelCFType.CellValue.
Example
Type of conditional formatting to be applied is based on the value set from ExcelCFType enumeration to FormatType property. Here for example, we set ExcelCFType.TimePeriod to FormatType property.
using Syncfusion.XlsIO;
using System;
            
class Example
{
    static void Main()
    {
        using (ExcelEngine excelEngine = new ExcelEngine())
        {
            //Create a worksheet.        
            IApplication application = excelEngine.Excel;
            application.DefaultVersion = ExcelVersion.Excel2013;
            IWorkbook workbook = application.Workbooks.Create(1);
            IWorksheet worksheet = workbook.Worksheets[0];
            
            //Load data to Apply Conditional Formatting.
            worksheet["B1"].Text = "Conditional Formats";
            worksheet["B2"].DateTime = DateTime.Today;
            worksheet["B3"].DateTime = DateTime.Parse("1/18/2015");
            worksheet["B4"].DateTime = DateTime.Today;
            worksheet["B5"].DateTime = DateTime.Today;
            worksheet["B6"].DateTime = DateTime.Parse("1/18/2016");
            worksheet["B7"].DateTime = DateTime.Today;
            worksheet["B8"].DateTime = DateTime.Today;
            worksheet["B9"].DateTime = DateTime.Parse("1/18/2017");
            worksheet["B10"].DateTime = DateTime.Today;
            worksheet["B11"].DateTime = DateTime.Today;
            
            //Create instance of IConditonalFormat and IConditionalFormats.
            IConditionalFormats formats = worksheet["B2:B11"].ConditionalFormats;
            IConditionalFormat format = formats.AddCondition();
            
            //Set FormatType.
            format.FormatType = ExcelCFType.TimePeriod;
            
            //Set TimePeriodType. (Condition)
            format.TimePeriodType = CFTimePeriods.ThisMonth;
            
            //Set NumberFormat.
            format.NumberFormat = "d-mmm";
            
            //Set color.
            format.BackColor = ExcelKnownColors.Red;
            
            //Save and Dispose.
            workbook.SaveAs("ConditionalFormats.xlsx");
            workbook.Close();
        }
    }
}
AssemblyVersion

Syncfusion.XlsIO.Base: 17.2460.0.34

See Also