ClosedXML使用公式使用条件格式时 – 公式不正确

我正在使用ClosedXML的条件格式,我有两个问题。 首先,如果我将条件设置为基于如下值:

> RangeToAdd.AddConditionalFormat().WhenLessThan(0).Fill.SetBackgroundColor(XLColor.Red).Font.SetFontColor(XLColor.Red); 

但是,当我需要将其设置为相对单元格时,它不起作用。 这是我试过的:

 RangeToAdd.AddConditionalFormat().WhenLessThan("\"=RC[-19]\"").Fill.SetBackgroundColor(XLColor.Yellow); RangeToAdd.AddConditionalFormat().WhenGreaterThan("\"=RC[-19]+RC[-18]+RC[-17]\"").Fill.SetBackgroundColor(XLColor.BabyBlue); 

它不工作。 这是添加=“=,然后是不正确的公式,我遵循在这里的文档中所说的,我也尝试了它,而不逃脱报价。

另一个问题很小,但我不明白。 如何设置一个条件停止的时候是真的。

您添加了太多的引号:按照文档简单

 WhenLessThan("=RC[-19]") // But Excel can't read it unfortunately 

一个可能的工作

 WhenLessThan("=" + RC(RangeToAdd,0,-19)) 

和类似地

 WhenGreaterThan("=" + RC(RangeToAdd,0,-19) + "+" + RC(RangeToAdd,0,-18) + "+" + RC(RangeToAdd,0,-17)) 

使用帮手

  static string RC(IXLRange range, int r, int c) { return range.FirstCell().CellBelow(r).CellRight(c).Address.ToString(XLReferenceStyle.A1); }