Show / Hide Table of Contents

Conditional Formatting Dates Occurring

Output: ConditionalFormattingDatesOccurring.xlsx

public void Run()
{
    var workbook = new Workbook();
    var worksheet = workbook.Worksheets[0];
    worksheet.Columns[0].WidthCharacters = 40;
    worksheet.Columns.SetWidthCharacters("B", "F", 5);

    worksheet["A1"].Value = "Date Tomorrow";
    worksheet.GetRange("B1:D1").SetFormula(new[] {"=NOW()-1", "=NOW()", "=NOW()+1"});
    var ruleB1 = worksheet.ConditionalFormattings.AddDatesOccurring("B1:D1", TimePeriod.Tomorrow);
    ruleB1.Fill = CellFill.CreateSolidFill(SpreadsheetColor.Accent1);

    worksheet["A2"].Value = "Date Last Month";
    worksheet.GetRange("B2:D2").SetFormula(new[] {"=EDATE(NOW(),-1)", "=NOW()", "=EDATE(NOW(),1)"});
    var ruleB2 = worksheet.ConditionalFormattings.AddDatesOccurring("B2:D2", TimePeriod.LastMonth);
    ruleB2.Fill = CellFill.CreateSolidFill(SpreadsheetColor.Accent1);

    workbook.SaveAs("ConditionalFormattingDatesOccurring.xlsx");
}
Back to top Generated by DocFX