Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# EPPlus条件格式_C#_.net_Epplus - Fatal编程技术网

C# EPPlus条件格式

C# EPPlus条件格式,c#,.net,epplus,C#,.net,Epplus,我试着遵循这一点: 但在我的例子中,excel文件已损坏,请给我删除规则后恢复的选项 我想实现这一点(简化): 这是我的代码(A列): 首先感谢大家,公式中缺少一个=。我不知道搜索($1;C2)的目的是什么,但下面的代码是有效的 //the range of cells to be searched var cells = new ExcelAddress("A1:Z10"); //the excel formula, note that it uses the top left cell

我试着遵循这一点:

但在我的例子中,excel文件已损坏,请给我删除规则后恢复的选项

我想实现这一点(简化):

这是我的代码(A列):


首先感谢大家,公式中缺少一个
=
。我不知道
搜索($1;C2)
的目的是什么,但下面的代码是有效的

//the range of cells to be searched
var cells = new ExcelAddress("A1:Z10");

//the excel formula, note that it uses the top left cell of the range
//so if the range was C5:d10, it would be =ISNUMBER(C5)
var formula = "=ISNUMBER(A1)";

var condition = worksheet.ConditionalFormatting.AddExpression(cells);
condition.Formula = formula;
condition.Style.Fill.PatternType = ExcelFillStyle.Solid;
condition.Style.Fill.BackgroundColor.Color = Color.Yellow;

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

作为对VDWWD的回应-我认为等号不是问题,如果公式中使用等号,我会得到损坏错误

从EPPlus文档中

  • 不要使用本地化的函数名。仅支持英文名称(如SUM、IF、VLOOKUP等)
  • 不要使用分号作为函数参数之间的分隔符。只支持逗号
  • 不要在公式中添加前导=符号。“=SUM(A1:A2)”是错误的,“SUM(A1:A2)”是正确的

首先尝试将条件格式添加到4个单元格中,A2、A3、A4、A5,而不是在一个范围内。当我尝试在一个范围内做时,我遇到了一些问题。啊,谢谢你指出:只支持逗号。我的Excel默认的分隔符是分号。啊,直到现在我才知道这是可能的。不确定是否要更改,但看起来可以通过语言设置更改(假设您在windows上):
//the range of cells to be searched
var cells = new ExcelAddress("A1:Z10");

//the excel formula, note that it uses the top left cell of the range
//so if the range was C5:d10, it would be =ISNUMBER(C5)
var formula = "=ISNUMBER(A1)";

var condition = worksheet.ConditionalFormatting.AddExpression(cells);
condition.Formula = formula;
condition.Style.Fill.PatternType = ExcelFillStyle.Solid;
condition.Style.Fill.BackgroundColor.Color = Color.Yellow;