EPPlus条件格式 [英] EPPlus Conditional Formatting

查看:252
本文介绍了EPPlus条件格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试遵循以下方法:使用EPPlus通过表达式进行条件格式化

I've tried to follow this one: Conditional Formatting by Expression using EPPlus

但是在我的情况下,excel文件已损坏,并提供了删除规则后恢复的选项。

But in my case, the excel file was corrupted and give me option to recover with rule removed.

我要实现此目标(简化):
屏幕快照

I want to achieve this (simplified): screenshot

这是我的代码(针对A列):

Here's my codes (for column A):

ExcelWorksheet ew = ep.Workbook.Worksheets.Add("Sheet1");

var cells = new ExcelAddress("A2:A5");
string formula = "ISNUMBER(SEARCH($A$1;C2))";
var condition = ew.ConditionalFormatting.AddExpression(cells);
condition.Formula = formula;
condition.Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
condition.Style.Fill.BackgroundColor.Color = System.Drawing.Color.Yellow;

预先感谢

推荐答案

出现错误错误的原因是公式中的分号。
在此公式中,分号不是有效的运算符。

The reason you're getting the corruption error is due to the semi colon in the formula. A semi-colon is not a valid operator in this formula.

针对VDWWD-我认为等号不是问题,我如果在公式中使用了等号,则会出现损坏错误。

In response to VDWWD - I don't think the equal sign is a problem, I get the corruption error if the equal sign is used in the formula.

摘自EPPlus文档


  • 不要使用本地化的函数名。仅支持英文名称(例如SUM,IF,VLOOKUP等)。

  • 请勿使用分号作为函数参数之间的分隔符。仅支持逗号。

  • 不要在公式中添加前导=符号。 = SUM(A1:A2)错误, SUM(A1:A2)是正确的。

Epplus公式计算

这篇关于EPPlus条件格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆