条件格式 excel epplus if (cell.value<0) 填红色

conditional format excel epplus if (cell.value<0) fill red

我正在尝试使用 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;

这工作正常,但如果我改变:

IF(OFFSET(J3,0,-1)-J3>0,1,0)

通过这个:

if(J3<0)

不起作用,打开时 Excel 说数据已损坏。

知道如何正确书写负值单元格吗?

excel 中的 IF 语句不再允许可选的 value_if_true 部分(我相信在旧版本中它确实存在):MS IF Documentation

因此将其更改为:

string _statement = "if(B3<0, 1)";