条件格式excel epplus if (cell.value<0) fill red
本文关键字:fill red value cell excel 格式 epplus if 条件 | 更新日期: 2023-09-27 18:16:58
我正在尝试使用EPPLUS将条件格式应用于Excel,以便在值为负时将一段单元格填充为红色。
如果单元格的值大于下一个单元格的值,则该单元格将被红色
填充 ExcelAddress _formatRangeAddress = new ExcelAddress("J2:J"+(listaMargenes.Count+2));
string _statement="IF(OFFSET(J3,0,-1)-J3>0,1,0)";
var _cond4 = hoja.ConditionalFormatting.AddExpression(_formatRangeAddress);
_cond4.Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
_cond4.Style.Fill.BackgroundColor.Color = System.Drawing.Color.Red;
_cond4.Formula = _statement;
this Works fine,但是如果我改变
IF(OFFSET(J3,0,-1)-J3>0,1,0)
由:if(J3<0)
不工作,当打开Excel显示有损坏的数据。
任何想法如何写正确的方式,把红色的细胞与负值?
excel中的IF
语句不再允许可选的value_if_true
部分(我相信在旧版本中它允许):MS IF文档
所以改成:
string _statement = "if(B3<0, 1)";