我试过这样做:使用EPPlus按表达式设置条件格式
但是在我的例子中,excel文件是损坏的,给了我恢复规则删除的选项。
我想实现这一点(简化):屏幕截图
这是我的代码(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;提前感谢
发布于 2018-10-10 13:39:17
您得到损坏错误的原因是由于公式中的分号。在这个公式中,分号不是有效的运算符.
作为对VDWWD的回应-我不认为等号是一个问题,如果在公式中使用等号,我会得到错误。
来自EPPlus文档
发布于 2018-10-10 13:28:53
首先,公式中缺少一个=。我不知道SEARCH($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;https://stackoverflow.com/questions/52737955
复制相似问题