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

时间:2015-10-09 09:58:14

标签: c# excel epplus

我正在尝试使用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时表示数据已损坏。

任何想法如何写出正确的方式,将红色单元格置为负值?

1 个答案:

答案 0 :(得分:1)

excel中的interface IMyMethodable { void MyMethod(); } interface I1 : IMyMethodable { void F1(); } interface I2 : IMyMethodable { void F2(); } //2 interfaces 语句不允许使用可选的IF部分(我相信它的旧版本):MS IF Documentation

因此将其更改为:

value_if_true
相关问题