繁体   English   中英

使用公式处理条件格式时使用ClosedXML-公式不正确

[英]ClosedXML when Working With Conditional Formats using formulas - the formula is incorrect

我在ClosedXML中使用条件格式,但有2个问题。 首先,如果我将条件设置为基于这样的值:

> 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);

而且它不起作用。 它先添加=“ =,然后添加不正确的公式。我按照此处文档中的说明进行操作并且尝试了转义,但也没有使用引号。

另一个问题很小,但我不知道。 如何设置为true时停止的条件。

您添加了太多的引号:根据文档,它只是

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);
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM