C# 如何在日期小于Epplus时添加条件格式

C# 如何在日期小于Epplus时添加条件格式,c#,conditional-formatting,epplus,date-range,C#,Conditional Formatting,Epplus,Date Range,我需要使用Epplus(最新版本4.1.0)根据日期设置条件格式 我设定了我的射程 var rng= new ExcelAddress(<startingRow>, <startingcolumn>,<endingRow>, <endingColumn>); 以及与AddLastWeek和AddLast7Days类似的格式 但这并不是一个完整的解决方案,其他预定义的Excel日期条件也没有多大帮助 我需要 var format1 = ws.Con

我需要使用Epplus(最新版本4.1.0)根据日期设置条件格式

我设定了我的射程

var rng= new ExcelAddress(<startingRow>, <startingcolumn>,<endingRow>, <endingColumn>);
以及与AddLastWeek和AddLast7Days类似的格式

但这并不是一个完整的解决方案,其他预定义的Excel日期条件也没有多大帮助

我需要

var format1 = ws.ConditionalFormatting.AddLessThan(rng).Formula;
format1.Formula = ???
我试图在公式中输入几个包含格式化日期的字符串,但它们被忽略了(没有错误,也没有格式化)。 在Excel中,我可以在管理条件格式表单中看到它们。 我发现如果我这样做

format1.Formula = "A1"
单元格A1包含格式为“今天”的日期,但我更喜欢不包含虚拟单元格的解决方案,因为以后我需要更多标准


你能告诉我解决这个问题的正确方法吗?

因为EPPlus没有内置功能,所以只能自己进行日期转换:

var ltecf = rng.ConditionalFormatting.AddLessThanOrEqual();
ltecf.Formula = DateTime.Now.Date.ToOADate().ToString(CultureInfo.InvariantCulture);
ltecf.Style.Fill.BackgroundColor.Color = Color.LightGreen;
var ltecf = rng.ConditionalFormatting.AddLessThanOrEqual();
ltecf.Formula = DateTime.Now.Date.ToOADate().ToString(CultureInfo.InvariantCulture);
ltecf.Style.Fill.BackgroundColor.Color = Color.LightGreen;