简体   繁体   English

你如何让ClosedXML使用公式的条件格式?

[英]How do you get ClosedXML to use conditional formatting with formulas?

According to the documentation you can add conditional formatting to a cell using the syntax: 根据文档,您可以使用以下语法向单元格添加条件格式:

.AddConditionalFormat().WhenEquals("=B1")

So I tried this: 所以我尝试了这个:

cell.AddConditionalFormat().WhenEquals("=F5=0")
    .Fill.SetBackgroundColor(XLColor.FromHtml("#f00"));

However, whenever I try this, load the spreadsheet into Excel, and look at the conditional formatting for the cell, it seems to have changed it to a simple 'cell value equals' type, rather than a formula type. 但是,每当我尝试这个时,将电子表格加载到Excel中,并查看单元格的条件格式,它似乎已将其更改为简单的“单元格值等于”类型,而不是公式类型。 So I see this: 所以我看到了这个:

在此输入图像描述

but what I want to see is this: 但我想看到的是:

在此输入图像描述

What am I missing!? 我错过了什么!?

After fruitlessly digging in Google for hours, I gave up and went back to basics. 在Google无数次挖掘数小时之后,我放弃了并回归基础。 I eventually noticed a method called WhenIsTrue() , which accepts a formula! 我最终注意到一个名为WhenIsTrue()的方法,它接受一个公式!

So, in case anyone else gets here looking for this (this question seems to be the second best ranking answer in Google for 'conditional formatting closedxml'), this is the answer. 所以,如果有其他人到这里寻找这个(这个问题似乎是Google中'条件格式化closedxml'的第二个最佳排名答案),这就是答案。

cell.AddConditionalFormat().WhenIsTrue("=F5=0")
    .Fill.SetBackgroundColor(XLColor.FromHtml("#f00"));

我能够像这样工作:

.AddConditionalFormat().WhenEquals("=$B1")

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

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