EPPlus条件格式化字符串整个列的长度 [英] EPPlus Conditional Formatting String Length of Entire Column
问题描述
我正在使用EPPlus生成具有验证和条件格式的Excel文档。我想检查单元格中文本的长度,如果它大于指定的长度,则用一种颜色填充它。我希望对整个专栏文章都这样做。
I am using EPPlus to generate Excel documents with validation and conditional formatting. I want to check the length of text in a cell and fill it with a color if it is greater than a specified length. I want this to be done for an entire column.
var address = new ExcelAddress("$A:$A");
var condition = workSheet.ConditionalFormatting.AddExpression(address);
condition.Formula = "=IF(LEN(A1)>25, TRUE, FALSE)";
condition.Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
condition.Style.Fill.BackgroundColor.Color = Color.Green;
当我打开生成的Excel电子表格时,它会显示错误,要求恢复数据。
When I open the generated excel spreadsheet it displays an error asking to recover data.
推荐答案
对于像我一样看着此线程并在打开excel时出错的人,请注意,您不能使用
For someone looking at this thread like I was and getting an error when opening the excel, note that you can't use "=" to start your conditional expression.
此外,我的Excel公式区域格式要求我应该使用;。表示多个参数,但在这种情况下,公式似乎像,作为分隔符。以下代码段应该起作用:
Also, my Excel formula regional formatting dictates that I should use ";" to indicate multiple parameters, but in this case the formula seems to like "," as a separator. The following snippet should work:
var address = new ExcelAddress("A2");
var condition = workSheet.ConditionalFormatting.AddExpression(address);
condition.Formula = "IF(LEN(A1)>25, TRUE, FALSE)";
condition.Style.Fill.BackgroundColor.Color = Color.Green;
这篇关于EPPlus条件格式化字符串整个列的长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!